@astryxdesign/cli 0.7.3 → 0.7.4-canary.1a552f2

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 (244) hide show
  1. package/README.md +63 -63
  2. package/api/component/_adapter.mjs +4 -3
  3. package/api/component/component.mjs +13 -6
  4. package/api/component/doc-links.test.mjs +33 -0
  5. package/api/discover/_adapter.mjs +22 -10
  6. package/api/discover/_catalog-view.d.mts +2 -0
  7. package/api/discover/_catalog-view.mjs +1 -0
  8. package/api/discover/_catalog-view.test.mjs +1 -0
  9. package/api/discover/detail/detail.mjs +1 -0
  10. package/api/discover/detail/detail.test.mjs +3 -0
  11. package/api/discover/detail/doc/doc.mjs +5 -1
  12. package/api/discover/detail/doc/doc.test.mjs +1 -0
  13. package/api/discover/detail/item/item.mjs +2 -0
  14. package/api/discover/detail/item/item.test.mjs +2 -0
  15. package/api/discover/discover.doc.mjs +4 -4
  16. package/api/discover/discover.type.d.mts +20 -0
  17. package/api/discover/discover.type.mjs +5 -0
  18. package/api/discover/list/list.test.mjs +2 -0
  19. package/api/discover/search/search.d.mts +3 -2
  20. package/api/discover/search/search.mjs +26 -7
  21. package/api/discover/search/search.test.mjs +67 -0
  22. package/api/docs/_adapter.d.mts +80 -0
  23. package/api/docs/_adapter.mjs +261 -11
  24. package/api/docs/detail/detail.mjs +8 -0
  25. package/api/docs/docOverlays.test.mjs +2 -1
  26. package/api/docs/docs.d.mts +16 -6
  27. package/api/docs/docs.doc.mjs +1 -1
  28. package/api/docs/docs.mjs +55 -6
  29. package/api/docs/docs.type.d.mts +28 -2
  30. package/api/docs/docs.type.mjs +13 -3
  31. package/api/docs/guide-route-targets.test.mjs +1002 -0
  32. package/api/docs/index/index.mjs +9 -0
  33. package/api/docs/integration-tree.test.mjs +22 -0
  34. package/api/docs/integrationDocs.test.mjs +85 -0
  35. package/api/docs/list/list.mjs +7 -1
  36. package/api/docs/node/node.mjs +9 -1
  37. package/api/docs/reference-blocks.test.mjs +1 -1
  38. package/api/doctor/_adapter.d.mts +40 -0
  39. package/api/doctor/_adapter.mjs +171 -1
  40. package/api/doctor/built-checks.d.mts +85 -0
  41. package/api/doctor/built-checks.mjs +837 -0
  42. package/api/doctor/built-checks.test.mjs +531 -0
  43. package/api/doctor/doctor.d.mts +6 -5
  44. package/api/doctor/doctor.doc.mjs +11 -1
  45. package/api/doctor/doctor.mjs +18 -3
  46. package/api/doctor/doctor.type.d.mts +6 -0
  47. package/api/doctor/doctor.type.mjs +3 -0
  48. package/api/hook/list/list.d.mts +1 -1
  49. package/api/integration/_adapter.d.mts +11 -2
  50. package/api/integration/_adapter.mjs +30 -4
  51. package/api/integration/authoring-checks.mjs +29 -2
  52. package/api/integration/authoring-checks.test.mjs +131 -1
  53. package/api/integration/check/check.d.mts +4 -1
  54. package/api/integration/check/check.mjs +34 -4
  55. package/api/integration/check/check.test.mjs +49 -0
  56. package/api/integration/integration-check.type.d.mts +8 -0
  57. package/api/integration/integration-check.type.mjs +4 -1
  58. package/api/integration/integrationCheck.doc.mjs +8 -1
  59. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  60. package/api/integration/pack-check.mjs +71 -2
  61. package/api/integration/pack-check.test.mjs +77 -0
  62. package/api/integration/validate-integration-case-disk.test.mjs +2 -0
  63. package/api/integration/validate-integration-gaps.test.mjs +7 -4
  64. package/api/integration/validate-integration.mjs +96 -14
  65. package/api/integration/validate-integration.type.d.mts +10 -4
  66. package/api/integration/validate-integration.type.mjs +10 -5
  67. package/api/integration/validateIntegration.doc.mjs +1 -1
  68. package/api/search/_candidate-score.d.mts +3 -2
  69. package/api/search/_candidate-score.mjs +66 -3
  70. package/api/search/_gather-docs.mjs +12 -2
  71. package/api/search/_priority.mjs +2 -1
  72. package/api/search/_score.d.mts +2 -1
  73. package/api/search/_score.mjs +2 -2
  74. package/api/search/search.doc.mjs +1 -1
  75. package/api/search/search.family-members.test.mjs +124 -0
  76. package/api/search/search.mjs +28 -0
  77. package/api/theme/palette/generate/generate.d.mts +8 -0
  78. package/api/theme/palette/generate/generate.mjs +38 -11
  79. package/api/theme/palette/generate/generate.test.mjs +83 -4
  80. package/api/theme/palette/generate/generator.d.mts +6 -0
  81. package/api/theme/palette/generate/generator.mjs +6 -0
  82. package/api/theme/theme.type.d.mts +12 -1
  83. package/api/theme/theme.type.mjs +7 -1
  84. package/api/theme/themeBuild.doc.mjs +1 -1
  85. package/api/theme/themeList.doc.mjs +1 -1
  86. package/api/theme/themePaletteGenerate.doc.mjs +1 -1
  87. package/api/theme/themeTargets.doc.mjs +1 -1
  88. package/assets/discover/official-packages.json +16 -0
  89. package/assets/docs/author-a-theme.doc.mjs +15 -15
  90. package/assets/docs/browser-support.doc.mjs +1 -1
  91. package/assets/docs/getting-started.doc.mjs +16 -16
  92. package/assets/docs/is-my-code-good.doc.mjs +6 -6
  93. package/assets/docs/styling-overview.doc.mjs +5 -5
  94. package/assets/docs/theme.doc.mjs +5 -5
  95. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  96. package/assets/docs/tree/add-a-theme.doc.mjs +2 -2
  97. package/assets/docs/tree/add-a-topic.doc.mjs +6 -6
  98. package/assets/docs/tree/agent-guidance.doc.mjs +5 -5
  99. package/assets/docs/tree/authoring.doc.mjs +2 -2
  100. package/assets/docs/tree/block-template.doc.mjs +1 -1
  101. package/assets/docs/tree/check-the-props.doc.mjs +3 -3
  102. package/assets/docs/tree/check-your-docs.doc.mjs +6 -6
  103. package/assets/docs/tree/checks.doc.mjs +11 -11
  104. package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
  105. package/assets/docs/tree/cli-command.doc.mjs +6 -6
  106. package/assets/docs/tree/codemods.doc.mjs +7 -7
  107. package/assets/docs/tree/component-family.doc.mjs +1 -1
  108. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  109. package/assets/docs/tree/component-lookups.doc.mjs +6 -5
  110. package/assets/docs/tree/computer-agent-guide.doc.mjs +7 -7
  111. package/assets/docs/tree/computer-integrations.doc.mjs +5 -5
  112. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +3 -3
  113. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  114. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  115. package/assets/docs/tree/doc-syntax.doc.mjs +219 -0
  116. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  117. package/assets/docs/tree/extend-or-replace.doc.mjs +39 -7
  118. package/assets/docs/tree/font-setup.doc.mjs +1 -1
  119. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  120. package/assets/docs/tree/global-integrations.doc.mjs +11 -11
  121. package/assets/docs/tree/global.doc.mjs +2 -2
  122. package/assets/docs/tree/host-entry.doc.mjs +1 -1
  123. package/assets/docs/tree/install-once.doc.mjs +4 -4
  124. package/assets/docs/tree/layout.doc.mjs +1 -1
  125. package/assets/docs/tree/links.doc.mjs +2 -2
  126. package/assets/docs/tree/migration-setup.doc.mjs +15 -15
  127. package/assets/docs/tree/migration.doc.mjs +2 -1
  128. package/assets/docs/tree/other-libraries.doc.mjs +1 -1
  129. package/assets/docs/tree/page-template.doc.mjs +2 -2
  130. package/assets/docs/tree/problems.doc.mjs +8 -8
  131. package/assets/docs/tree/project-global-or-both.doc.mjs +2 -2
  132. package/assets/docs/tree/publishing.doc.mjs +7 -7
  133. package/assets/docs/tree/quick-start.doc.mjs +9 -9
  134. package/assets/docs/tree/reference.doc.mjs +2 -2
  135. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  136. package/assets/docs/tree/replace-a-core-template.doc.mjs +4 -4
  137. package/assets/docs/tree/scaffold.doc.mjs +1 -1
  138. package/assets/docs/tree/sections-and-placement.doc.mjs +3 -3
  139. package/assets/docs/tree/see-it-in-an-app.doc.mjs +3 -3
  140. package/assets/docs/tree/short-and-findable.doc.mjs +3 -3
  141. package/assets/docs/tree/single-component.doc.mjs +4 -4
  142. package/assets/docs/tree/start-a-template.doc.mjs +5 -5
  143. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  144. package/assets/docs/tree/styling-libraries.doc.mjs +2 -1
  145. package/assets/docs/tree/styling.doc.mjs +1 -1
  146. package/assets/docs/tree/tailwind.doc.mjs +1 -1
  147. package/assets/docs/tree/test-in-an-app.doc.mjs +5 -5
  148. package/assets/docs/tree/test-template-in-app.doc.mjs +6 -6
  149. package/assets/docs/tree/tokens-and-setup.doc.mjs +1 -1
  150. package/assets/docs/tree/troubleshooting.doc.mjs +24 -20
  151. package/assets/docs/tree/uninstall.doc.mjs +2 -2
  152. package/assets/docs/tree/updates.doc.mjs +1 -1
  153. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  154. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  155. package/assets/docs/tree/verify-packed-template.doc.mjs +3 -3
  156. package/assets/docs/tree/versioning.doc.mjs +4 -4
  157. package/assets/docs/tree/who-answers.doc.mjs +4 -4
  158. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -4
  159. package/assets/docs/use-a-theme.doc.mjs +10 -10
  160. package/assets/docs/use-integrations.doc.mjs +1 -1
  161. package/assets/docs/working-with-ai.doc.mjs +15 -15
  162. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +1 -1
  163. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +1 -1
  164. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +54 -0
  165. package/assets/templates/themes/butter/butterPalettes.generated.receipt.json +1499 -0
  166. package/assets/templates/themes/butter/butterPalettes.generated.ts +550 -0
  167. package/assets/templates/themes/butter/butterTheme.ts +274 -234
  168. package/assets/templates/themes/butter/palette.config.json +484 -0
  169. package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +41 -0
  170. package/assets/templates/themes/gothic/gothicPalettes.generated.receipt.json +979 -0
  171. package/assets/templates/themes/gothic/gothicPalettes.generated.ts +271 -0
  172. package/assets/templates/themes/gothic/gothicTheme.ts +130 -160
  173. package/assets/templates/themes/gothic/palette.config.json +371 -0
  174. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +51 -0
  175. package/assets/templates/themes/matcha/matchaPalettes.generated.receipt.json +1502 -0
  176. package/assets/templates/themes/matcha/matchaPalettes.generated.ts +501 -0
  177. package/assets/templates/themes/matcha/matchaPalettes.ts +21 -0
  178. package/assets/templates/themes/matcha/matchaTheme.ts +164 -103
  179. package/assets/templates/themes/matcha/palette.config.json +448 -0
  180. package/assets/templates/themes/stone/palette.config.json +262 -0
  181. package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +51 -0
  182. package/assets/templates/themes/stone/stonePalettes.generated.receipt.json +840 -0
  183. package/assets/templates/themes/stone/stonePalettes.generated.ts +501 -0
  184. package/assets/templates/themes/stone/stoneTheme.ts +190 -207
  185. package/assets/templates/themes/y2k/palette.config.json +166 -0
  186. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +54 -0
  187. package/assets/templates/themes/y2k/y2kPalettes.generated.receipt.json +872 -0
  188. package/assets/templates/themes/y2k/y2kPalettes.generated.ts +550 -0
  189. package/assets/templates/themes/y2k/y2kPalettes.ts +257 -0
  190. package/assets/templates/themes/y2k/y2kTheme.ts +164 -391
  191. package/authoring/codemod/codemod.doc.mjs +1 -1
  192. package/authoring/config/config.doc.mjs +4 -4
  193. package/authoring/debug/parse.d.mts +1 -1
  194. package/authoring/discover/discover.doc.mjs +1 -1
  195. package/authoring/doctypes/_schema.d.mts +4 -0
  196. package/authoring/doctypes/_schema.mjs +4 -0
  197. package/authoring/doctypes/reference/type.ts +14 -2
  198. package/authoring/gap-report/gap-report.doc.mjs +1 -1
  199. package/authoring/integration/integration.doc.mjs +6 -6
  200. package/clients/cli/commands/discover.mjs +1 -1
  201. package/clients/cli/commands/discover.sources.test.mjs +6 -0
  202. package/clients/cli/commands/docs.doc.mjs +1 -1
  203. package/clients/cli/commands/docs.mjs +27 -2
  204. package/clients/cli/commands/docs.test.mjs +1 -1
  205. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  206. package/clients/cli/commands/doctor.doc.mjs +13 -1
  207. package/clients/cli/commands/doctor.mjs +25 -9
  208. package/clients/cli/commands/integration-check.doc.mjs +11 -0
  209. package/clients/cli/commands/integration-check.test.mjs +36 -3
  210. package/clients/cli/commands/integration-pack.doc.mjs +1 -1
  211. package/clients/cli/commands/integration-verify.doc.mjs +1 -1
  212. package/clients/cli/commands/integration.mjs +15 -3
  213. package/clients/cli/commands/theme-targets.doc.mjs +1 -1
  214. package/clients/cli/commands/upgrade.doc.mjs +2 -2
  215. package/clients/cli/lib/define-command.mjs +5 -3
  216. package/foundation/agent-docs/agent-docs.d.mts +14 -2
  217. package/foundation/agent-docs/agent-docs.mjs +65 -4
  218. package/foundation/agent-docs/agent-docs.test.mjs +107 -0
  219. package/foundation/discovery/docs-discovery.d.mts +93 -2
  220. package/foundation/discovery/docs-discovery.mjs +237 -8
  221. package/foundation/discovery/runner-allowlist.d.mts +2 -0
  222. package/foundation/discovery/runner-allowlist.mjs +4 -0
  223. package/foundation/discovery/runner-commands.d.mts +29 -13
  224. package/foundation/discovery/runner-commands.mjs +253 -17
  225. package/foundation/discovery/stray-pointers.mjs +11 -5
  226. package/foundation/discovery/stray-pointers.test.mjs +6 -0
  227. package/foundation/doc-compiler/compile.mjs +8 -1
  228. package/foundation/doc-compiler/doc-loads.test.mjs +3 -0
  229. package/foundation/doc-compiler/doc-syntax.d.mts +194 -0
  230. package/foundation/doc-compiler/doc-syntax.mjs +739 -0
  231. package/foundation/doc-compiler/doc-syntax.test.mjs +383 -0
  232. package/foundation/doc-compiler/links.d.mts +13 -16
  233. package/foundation/doc-compiler/links.mjs +40 -7
  234. package/foundation/doc-compiler/tree.d.mts +5 -0
  235. package/foundation/doc-compiler/tree.mjs +9 -0
  236. package/foundation/env/package-manager.d.mts +18 -0
  237. package/foundation/env/package-manager.mjs +40 -0
  238. package/foundation/integrations/cli-requirement.d.mts +29 -0
  239. package/foundation/integrations/cli-requirement.mjs +47 -0
  240. package/foundation/integrations/cli-requirement.test.mjs +23 -2
  241. package/foundation/response/error-codes.test.mjs +9 -0
  242. package/foundation/response/response-types.doc.mjs +11 -11
  243. package/foundation/response/response-types.doc.test.mjs +29 -0
  244. package/package.json +9 -9
@@ -718,7 +718,7 @@ export async function linkSearchResponse(response, cwd) {
718
718
  result =>
719
719
  result?.domain === 'component' &&
720
720
  typeof result.description === 'string' &&
721
- result.description.includes('{@link'),
721
+ result.description.includes('{@'),
722
722
  )
723
723
  ) {
724
724
  return response;
@@ -728,7 +728,7 @@ export async function linkSearchResponse(response, cwd) {
728
728
  if (
729
729
  result?.domain !== 'component' ||
730
730
  typeof result.description !== 'string' ||
731
- !result.description.includes('{@link')
731
+ !result.description.includes('{@')
732
732
  ) {
733
733
  linked.push(result);
734
734
  continue;
@@ -767,7 +767,8 @@ export async function linkComponentResponse(response, cwd) {
767
767
  ) {
768
768
  return response;
769
769
  }
770
- if (!JSON.stringify(response.data ?? null).includes('{@link')) {
770
+ // Doc tokens render in the same pass as links.
771
+ if (!JSON.stringify(response.data ?? null).includes('{@')) {
771
772
  return response;
772
773
  }
773
774
  const catalog = await loadDocsCatalog(cwd);
@@ -12,6 +12,10 @@
12
12
  * Every leaf is also re-exported for direct scripting use.
13
13
  */
14
14
 
15
+ import {
16
+ docPackageManager,
17
+ runWithDocPackageManager,
18
+ } from '../../foundation/env/package-manager.mjs';
15
19
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
16
20
  import {AstryxError} from '../error.mjs';
17
21
  import {
@@ -258,13 +262,16 @@ async function componentBatch(selectors, options, coreDir) {
258
262
  * )>}
259
263
  */
260
264
  export async function component(name, options = {}) {
265
+ const cwd = options.cwd ?? process.cwd();
261
266
  // Every read resolves the links in the doc text it returns (spec:AST-047
262
- // FR9); a batch's results are each a read of their own.
263
- return /** @type {any} */ (
264
- await linkComponentResponse(
265
- await componentRead(name, options),
266
- options.cwd ?? process.cwd(),
267
- )
267
+ // FR9); a batch's results are each a read of their own. Doc tokens render
268
+ // for the project in `cwd`.
269
+ return runWithDocPackageManager(
270
+ docPackageManager(cwd),
271
+ async () =>
272
+ /** @type {any} */ (
273
+ await linkComponentResponse(await componentRead(name, options), cwd)
274
+ ),
268
275
  );
269
276
  }
270
277
 
@@ -219,6 +219,39 @@ describe("a link in a component doc's text", () => {
219
219
  });
220
220
  });
221
221
 
222
+ describe("doc tokens in a component doc's text", () => {
223
+ it(
224
+ 'render with no link beside them, in the read and in search, for the project in cwd',
225
+ async () => {
226
+ scaffold();
227
+ fs.writeFileSync(path.join(tmpDir, 'bun.lock'), '{}\n');
228
+ const docFile = path.join(
229
+ tmpDir,
230
+ 'node_modules/@acme/widgets/components/AcmeButton.doc.mjs',
231
+ );
232
+ fs.writeFileSync(
233
+ docFile,
234
+ `export default ${JSON.stringify({
235
+ ...ACME_BUTTON,
236
+ usage: {
237
+ description:
238
+ 'A button. Install with {@pm install @acme/widgets}; check with {@command doctor}.',
239
+ },
240
+ props: [],
241
+ examples: [],
242
+ })};\n`,
243
+ );
244
+ const read = /** @type {any} */ (
245
+ await component('AcmeButton', {cwd: tmpDir})
246
+ );
247
+ expect(read.data.usage.description).toBe(
248
+ 'A button. Install with `bun add @acme/widgets`; check with `astryx doctor`.',
249
+ );
250
+ },
251
+ SLOW,
252
+ );
253
+ });
254
+
222
255
  describe("a link in a topic's description", () => {
223
256
  it(
224
257
  'reads as the command that opens its doc, in the detail and the list',
@@ -27,10 +27,7 @@ import {
27
27
  import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
28
28
  import {projectAddCommand} from '../../foundation/release/notices.mjs';
29
29
  import {hostedRun} from '../../foundation/runtime/package-root.mjs';
30
- import {
31
- scanAllPackages,
32
- findComponentInPackages,
33
- } from './_package-scanner.mjs';
30
+ import {scanAllPackages, findComponentInPackages} from './_package-scanner.mjs';
34
31
  import {loadDocs} from '../../foundation/discovery/component-loader.mjs';
35
32
  import {collectIdentities} from '../../foundation/integrations/contribution-inventory.mjs';
36
33
  import {detectPackageManager} from '../../foundation/env/package-manager.mjs';
@@ -146,8 +143,7 @@ function validateDocs(docs) {
146
143
  return 'docs.name is missing or not a string';
147
144
  if (!d.usage || typeof d.usage.description !== 'string')
148
145
  return 'docs.usage.description is missing or not a string';
149
- if (d.props && !Array.isArray(d.props))
150
- return 'docs.props must be an array';
146
+ if (d.props && !Array.isArray(d.props)) return 'docs.props must be an array';
151
147
  if (d.components && !Array.isArray(d.components))
152
148
  return 'docs.components must be an array';
153
149
  if (d.usage?.bestPractices && !Array.isArray(d.usage.bestPractices))
@@ -286,6 +282,7 @@ export async function computerAvailableEntries(project, installed, declared) {
286
282
  const have = new Set([...installed.map(pkg => pkg.name), ...declared]);
287
283
  return (await availableComputerIntegrations(cwd, have)).map(c => ({
288
284
  name: c.name,
285
+ package: c.name,
289
286
  components: [],
290
287
  ...(c.version ? {version: c.version} : {}),
291
288
  ...(c.description ? {description: c.description} : {}),
@@ -597,7 +594,10 @@ async function callOwnSources(project, request = {}, options = {}) {
597
594
  }
598
595
  for (const integration of project?.loadedIntegrations ?? []) {
599
596
  if (integration.__discoverError) {
600
- origins.push({from: integration.name, error: integration.__discoverError});
597
+ origins.push({
598
+ from: integration.name,
599
+ error: integration.__discoverError,
600
+ });
601
601
  } else if (integration.__discover) {
602
602
  origins.push({from: integration.name, source: integration.__discover});
603
603
  }
@@ -617,7 +617,10 @@ async function callOwnSources(project, request = {}, options = {}) {
617
617
  /** @type {Set<string>} */
618
618
  const seen = new Set();
619
619
  const ask = request.package
620
- ? {package: request.package, ...(request.version ? {version: request.version} : {})}
620
+ ? {
621
+ package: request.package,
622
+ ...(request.version ? {version: request.version} : {}),
623
+ }
621
624
  : {};
622
625
  for (const {from, key = from, source, error} of origins) {
623
626
  if (source == null) {
@@ -645,7 +648,12 @@ async function callOwnSources(project, request = {}, options = {}) {
645
648
  const message = err instanceof Error ? err.message : String(err);
646
649
  const saved = readSavedCopy(file, label);
647
650
  if (saved == null) {
648
- result.sources.push({name: from, from, status: 'failed', error: message});
651
+ result.sources.push({
652
+ name: from,
653
+ from,
654
+ status: 'failed',
655
+ error: message,
656
+ });
649
657
  continue;
650
658
  }
651
659
  catalog = saved.catalog;
@@ -940,6 +948,7 @@ export function toEntry(pkg) {
940
948
  /** @type {Record<string, unknown>} */
941
949
  const entry = {
942
950
  name: pkg.name,
951
+ package: pkg.name,
943
952
  category: pkg.category,
944
953
  components: pkg.components,
945
954
  version: pkg.version,
@@ -979,7 +988,10 @@ export async function loadValidatedDoc(result, {lang, zh}) {
979
988
  try {
980
989
  docs = await loadDocs(
981
990
  result.docPath,
982
- /** @type {{zh?: boolean, dense?: boolean, lang?: string}} */ ({zh, lang}),
991
+ /** @type {{zh?: boolean, dense?: boolean, lang?: string}} */ ({
992
+ zh,
993
+ lang,
994
+ }),
983
995
  );
984
996
  } catch (e) {
985
997
  throw new AstryxError(
@@ -63,6 +63,7 @@ export function catalogEntry(pkg: CatalogPackage, version: string | undefined):
63
63
  description?: string | undefined;
64
64
  version?: string | undefined;
65
65
  name: string;
66
+ package: string;
66
67
  category: string;
67
68
  components: string[];
68
69
  };
@@ -85,6 +86,7 @@ export function availableEntries(catalog: CatalogResult, installed: InstalledPac
85
86
  description?: string | undefined;
86
87
  version?: string | undefined;
87
88
  name: string;
89
+ package: string;
88
90
  components: string[];
89
91
  }[];
90
92
  /**
@@ -102,6 +102,7 @@ export function catalogEntry(pkg, version) {
102
102
  const {components, ...others} = kindLists(pkg.contributions);
103
103
  return {
104
104
  name: pkg.package,
105
+ package: pkg.package,
105
106
  category: pkg.package,
106
107
  components,
107
108
  ...(version ? {version} : {}),
@@ -74,6 +74,7 @@ describe('availableEntries', () => {
74
74
  it('describes an entry the way an installed one is described', () => {
75
75
  expect(availableEntries(CATALOG, [], new Set())[1]).toEqual({
76
76
  name: '@acme/charts',
77
+ package: '@acme/charts',
77
78
  components: [],
78
79
  version: '2.0.0',
79
80
  themes: ['ocean'],
@@ -80,6 +80,7 @@ export function detail(packages, name, options = {}) {
80
80
  if (catalog) data.versions = catalog.versions;
81
81
  return {
82
82
  type: 'discover.detail',
83
+ package: String(data.name),
83
84
  data: /** @type {import('../discover.type.mjs').DiscoverDetailResponse['data']} */ (
84
85
  data
85
86
  ),
@@ -31,8 +31,10 @@ describe('discover.detail leaf', () => {
31
31
  it('projects the matched package into a detail entry', () => {
32
32
  const res = detail(PACKAGES, '@acme/widgets');
33
33
  expect(res.type).toBe('discover.detail');
34
+ expect(res.package).toBe('@acme/widgets');
34
35
  expect(res.data).toEqual({
35
36
  name: '@acme/widgets',
37
+ package: '@acme/widgets',
36
38
  category: '@acme/widgets',
37
39
  components: ['Alpha', 'Beta'],
38
40
  version: '1.2.3',
@@ -81,6 +83,7 @@ describe('discover.detail leaf with a discover source', () => {
81
83
  it('describes a package the project does not have, with the command that adds it', () => {
82
84
  expect(detail(PACKAGES, '@acme/charts', {catalog, add}).data).toEqual({
83
85
  name: '@acme/charts',
86
+ package: '@acme/charts',
84
87
  category: '@acme/charts',
85
88
  components: ['Chart'],
86
89
  version: '2.0.0',
@@ -35,7 +35,11 @@ export async function docFromResult(result, opts) {
35
35
  {type: 'component.detail', package: result.pkg.name, data},
36
36
  process.cwd(),
37
37
  );
38
- return {type: 'discover.detail.doc', data: linked.data};
38
+ return {
39
+ type: 'discover.detail.doc',
40
+ package: result.pkg.name,
41
+ data: linked.data,
42
+ };
39
43
  }
40
44
 
41
45
  /**
@@ -86,6 +86,7 @@ describe('discover.detail.doc leaf', () => {
86
86
  );
87
87
  expect(res).toEqual({
88
88
  type: 'discover.detail.doc',
89
+ package: '@acme/widgets',
89
90
  data: {name: 'Beta', usage: {description: 'Beta component'}, props: []},
90
91
  });
91
92
  });
@@ -39,6 +39,7 @@ export function item(packages, packageName, itemName, options = {}) {
39
39
  if (Array.isArray(names) && names.includes(itemName)) {
40
40
  return {
41
41
  type: 'discover.item',
42
+ package: packageName,
42
43
  data: {
43
44
  package: packageName,
44
45
  ...(pkg.version ? {version: pkg.version} : {}),
@@ -59,6 +60,7 @@ export function item(packages, packageName, itemName, options = {}) {
59
60
  const shown = version ?? defaultVersion(catalog);
60
61
  return {
61
62
  type: 'discover.item',
63
+ package: packageName,
62
64
  data: {
63
65
  package: packageName,
64
66
  ...(shown ? {version: shown} : {}),
@@ -38,6 +38,7 @@ describe('discover.item leaf', () => {
38
38
  it("finds an installed package's own template, doc, theme, or codemod", () => {
39
39
  expect(item(PACKAGES, '@acme/widgets', 'pages/Home')).toEqual({
40
40
  type: 'discover.item',
41
+ package: '@acme/widgets',
41
42
  data: {
42
43
  package: '@acme/widgets',
43
44
  version: '1.2.3',
@@ -53,6 +54,7 @@ describe('discover.item leaf', () => {
53
54
  item(PACKAGES, '@acme/charts', 'pages/report', {catalog: CATALOG, add}),
54
55
  ).toEqual({
55
56
  type: 'discover.item',
57
+ package: '@acme/charts',
56
58
  data: {
57
59
  package: '@acme/charts',
58
60
  version: '2.0.0',
@@ -91,22 +91,22 @@ export const doc = {
91
91
  {
92
92
  type: 'discover.list',
93
93
  description:
94
- 'What the project has: the integrations it loads and the official packages it declares (name, category, components, version, and a list per other kind they add), official packages first. meta.available lists what the project could add, official packages first, each with the command that adds it; inside a project, an integration installed for the computer that the project does not install is listed there too, with source `installed for this computer` and the install command for the project in `install`. meta.sources reports each source, the official list last. When it lists no integration it carries meta.configured.',
94
+ 'What the project has: the integrations it loads and the official packages it declares (package, the npm package and always equal to name; name, category, components, version, and a list per other kind they add), official packages first. meta.available lists what the project could add, official packages first, each with its package and the command that adds it; inside a project, an integration installed for the computer that the project does not install is listed there too, with source `installed for this computer` and the install command for the project in `install`. meta.sources reports each source, the official list last. When it lists no integration it carries meta.configured.',
95
95
  },
96
96
  {
97
97
  type: 'discover.detail',
98
98
  description:
99
- "One package: what the shown version adds, whether the project has it, its versions and latest release when a source knows them, and the command that adds it when the project does not have it. An entry from the official list lists the newest release this CLI knows as latest and the project's Core version; its add command pins the project's Core version, else the Core range it declares (quoted), else the latest release. A version or item the official list does not show answers ERR_UNKNOWN_PACKAGE.",
99
+ "One package: its package (the npm package the result is about), what the shown version adds, whether the project has it, its versions and latest release when a source knows them, and the command that adds it when the project does not have it. An entry from the official list lists the newest release this CLI knows as latest and the project's Core version; its add command pins the project's Core version, else the Core range it declares (quoted), else the latest release. A version or item the official list does not show answers ERR_UNKNOWN_PACKAGE.",
100
100
  },
101
101
  {
102
102
  type: 'discover.detail.doc',
103
103
  description:
104
- 'The validated ComponentDoc for one installed component, for an @scope/name/Component query.',
104
+ 'The validated ComponentDoc for one installed component, for an @scope/name/Component query, plus package, the npm package that owns the component.',
105
105
  },
106
106
  {
107
107
  type: 'discover.item',
108
108
  description:
109
- 'One item that is not an installed component: its kind, name, the package and version that add it, and whether the project has the package.',
109
+ 'One item that is not an installed component: its kind, name, the package and version that add it, and whether the project has the package. The envelope\'s package names the same package.',
110
110
  },
111
111
  {
112
112
  type: 'discover.search',
@@ -42,6 +42,10 @@ export type DiscoverListMeta = {
42
42
  */
43
43
  export type DiscoverListEntry = {
44
44
  name: string;
45
+ /**
46
+ * The npm package — always equal to `name`.
47
+ */
48
+ package: string;
45
49
  category: string;
46
50
  components: string[];
47
51
  version?: string | undefined;
@@ -77,6 +81,10 @@ export type DiscoverListEntry = {
77
81
  */
78
82
  export type DiscoverAvailableEntry = {
79
83
  name: string;
84
+ /**
85
+ * The npm package — always equal to `name`.
86
+ */
87
+ package: string;
80
88
  /**
81
89
  * Its latest release.
82
90
  */
@@ -127,6 +135,10 @@ export type DiscoverSourceState = {
127
135
  */
128
136
  export type DiscoverDetailResponse = {
129
137
  type: "discover.detail";
138
+ /**
139
+ * The npm package this result is about.
140
+ */
141
+ package: string;
130
142
  /**
131
143
  * `installed` says whether the project has the package;
132
144
  * `installedVersion` is set when it has another version than the one shown.
@@ -150,6 +162,10 @@ export type DiscoverDetailResponse = {
150
162
  */
151
163
  export type DiscoverDetailDocResponse = {
152
164
  type: "discover.detail.doc";
165
+ /**
166
+ * The npm package that owns the component.
167
+ */
168
+ package: string;
153
169
  data: import("@astryxdesign/cli/authoring").ComponentDoc;
154
170
  };
155
171
  /**
@@ -157,6 +173,10 @@ export type DiscoverDetailDocResponse = {
157
173
  */
158
174
  export type DiscoverItemResponse = {
159
175
  type: "discover.item";
176
+ /**
177
+ * The npm package that owns the item.
178
+ */
179
+ package: string;
160
180
  data: {
161
181
  package: string;
162
182
  version?: string;
@@ -44,6 +44,7 @@
44
44
  * An installed integration, or an official package the project declares.
45
45
  * @typedef {object} DiscoverListEntry
46
46
  * @property {string} name
47
+ * @property {string} package The npm package — always equal to `name`.
47
48
  * @property {string} category
48
49
  * @property {string[]} components
49
50
  * @property {string} [version]
@@ -61,6 +62,7 @@
61
62
  * A package the project could add.
62
63
  * @typedef {object} DiscoverAvailableEntry
63
64
  * @property {string} name
65
+ * @property {string} package The npm package — always equal to `name`.
64
66
  * @property {string} [version] Its latest release.
65
67
  * @property {string[]} components
66
68
  * @property {string[]} [templates]
@@ -95,6 +97,7 @@
95
97
  * astryx --json discover @scope/name[@version]
96
98
  * @typedef {object} DiscoverDetailResponse
97
99
  * @property {'discover.detail'} type
100
+ * @property {string} package The npm package this result is about.
98
101
  * @property {DiscoverListEntry & {
99
102
  * installed: boolean,
100
103
  * installedVersion?: string,
@@ -115,6 +118,7 @@
115
118
  * astryx --json discover @scope/name/Component
116
119
  * @typedef {object} DiscoverDetailDocResponse
117
120
  * @property {'discover.detail.doc'} type
121
+ * @property {string} package The npm package that owns the component.
118
122
  * @property {import('@astryxdesign/cli/authoring').ComponentDoc} data
119
123
  */
120
124
 
@@ -123,6 +127,7 @@
123
127
  * installed component.
124
128
  * @typedef {object} DiscoverItemResponse
125
129
  * @property {'discover.item'} type
130
+ * @property {string} package The npm package that owns the item.
126
131
  * @property {{
127
132
  * package: string,
128
133
  * version?: string,
@@ -32,6 +32,7 @@ describe('discover.list leaf', () => {
32
32
  expect(res.data).toEqual([
33
33
  {
34
34
  name: '@acme/widgets',
35
+ package: '@acme/widgets',
35
36
  category: '@acme/widgets',
36
37
  components: ['Alpha', 'Beta'],
37
38
  version: '1.2.3',
@@ -77,6 +78,7 @@ describe('discover.list leaf with discover sources', () => {
77
78
  expect(res.data).toEqual([
78
79
  {
79
80
  name: '@acme/widgets',
81
+ package: '@acme/widgets',
80
82
  category: '@acme/widgets',
81
83
  components: ['Alpha'],
82
84
  version: '1.2.3',
@@ -4,8 +4,9 @@
4
4
  /**
5
5
  * Search all packages for `query` (a free-text term that never starts with
6
6
  * `@`). Resolves to a search response when anything matches, even a single
7
- * item or an exact component name, or throws AstryxError (ERR_NOT_FOUND) —
8
- * with fuzzy suggestions when any exist.
7
+ * item, an exact component name or a near-miss name long enough to be a
8
+ * typo, or throws AstryxError (ERR_NOT_FOUND) — with fuzzy suggestions when
9
+ * any exist.
9
10
  *
10
11
  * @param {ScannedPackage[]} packages installed packages
11
12
  * @param {string} query
@@ -6,9 +6,12 @@
6
6
  *
7
7
  * A free-text query always answers with a list, so its response type depends
8
8
  * on the form of the query and never on what the project has:
9
- * 1. any matches -> discover.search
10
- * 2. fuzzy hits (distance <= 3) -> throw ERR_NOT_FOUND with suggestions
11
- * 3. otherwise -> throw ERR_NOT_FOUND
9
+ * 1. any matches, a near-miss name included -> discover.search (a one- to
10
+ * three-edit miss counts when both words are long enough: 5, 8 and 11
11
+ * letters)
12
+ * 2. other fuzzy hits (distance <= 3) -> throw ERR_NOT_FOUND with
13
+ * suggestions
14
+ * 3. otherwise -> throw ERR_NOT_FOUND
12
15
  * Matches are installed components, the project's other installed items,
13
16
  * packages, and every item a source lists for a package the project could add.
14
17
  * A caller opens one item by its package path, which ../detail answers.
@@ -31,7 +34,8 @@ const KIND_ORDER = ['package', ...DISCOVER_KINDS];
31
34
 
32
35
  /**
33
36
  * How well an item matches: 0 exact name, 1 name prefix, 2 name substring,
34
- * 3 title, summary, keyword, or description; null for no match.
37
+ * 3 a near-miss name (3.0, 3.1, 3.2 for one, two or three edits), 4 title,
38
+ * summary, keyword, or description; null for no match.
35
39
  * @param {SearchItem} item
36
40
  * @param {string} lower
37
41
  * @returns {number | null}
@@ -41,6 +45,19 @@ function rank(item, lower) {
41
45
  if (name === lower) return 0;
42
46
  if (name.startsWith(lower)) return 1;
43
47
  if (name.includes(lower)) return 2;
48
+ // A near-miss name ranks above a match in the title or text: how closely
49
+ // the name matches decides first (AST-051 FR4).
50
+ // Typo tolerance: same minimum-length guards as search (api/search/search.mjs).
51
+ // A one-edit miss is a typo only on words long enough that one edit rarely
52
+ // makes a different real word.
53
+ const dist = levenshteinDistance(lower, name);
54
+ if (dist >= 1 && dist <= 3) {
55
+ /** @type {Record<number, number>} */
56
+ const MIN_LENGTHS = {1: 5, 2: 8, 3: 11};
57
+ if (Math.min(lower.length, name.length) >= MIN_LENGTHS[dist]) {
58
+ return 3 + (dist - 1) / 10;
59
+ }
60
+ }
44
61
  const text = [
45
62
  item.title,
46
63
  item.summary,
@@ -50,14 +67,16 @@ function rank(item, lower) {
50
67
  .filter(Boolean)
51
68
  .join('\n')
52
69
  .toLowerCase();
53
- return text.includes(lower) ? 3 : null;
70
+ if (text.includes(lower)) return 4;
71
+ return null;
54
72
  }
55
73
 
56
74
  /**
57
75
  * Search all packages for `query` (a free-text term that never starts with
58
76
  * `@`). Resolves to a search response when anything matches, even a single
59
- * item or an exact component name, or throws AstryxError (ERR_NOT_FOUND) —
60
- * with fuzzy suggestions when any exist.
77
+ * item, an exact component name or a near-miss name long enough to be a
78
+ * typo, or throws AstryxError (ERR_NOT_FOUND) — with fuzzy suggestions when
79
+ * any exist.
61
80
  *
62
81
  * @param {ScannedPackage[]} packages installed packages
63
82
  * @param {string} query
@@ -142,6 +142,73 @@ describe('discover.search leaf — empty query (parity with api/search)', () =>
142
142
  });
143
143
  });
144
144
 
145
+ describe('discover.search leaf — typo tolerance (parity with api/search)', () => {
146
+ it('a one-edit miss on a 5+ letter name returns results, not ERR_NOT_FOUND', async () => {
147
+ // 'Alphe' is one substitution from 'Alpha' (distance 1, both >= 5 chars)
148
+ const res = await search(packages, 'Alphe', {});
149
+ expect(res.type).toBe('discover.search');
150
+ expect(res.data.matches.map(m => m.component)).toContain('Alpha');
151
+ });
152
+
153
+ it("ranks a near-miss name above a match in another item's text", async () => {
154
+ const items = [
155
+ {
156
+ package: '@acme/charts',
157
+ kind: 'component',
158
+ name: 'Scheduler',
159
+ description: 'Lighter than a Calendr widget',
160
+ installed: false,
161
+ },
162
+ {
163
+ package: '@acme/charts',
164
+ kind: 'component',
165
+ name: 'Calendar',
166
+ installed: false,
167
+ },
168
+ ];
169
+ // 'Calendr' is one edit from the name 'Calendar' and appears word for
170
+ // word only in Scheduler's description.
171
+ const res = await search(packages, 'Calendr', {items});
172
+ const names = res.data.matches.map(m => m.component);
173
+ expect(names.indexOf('Calendar')).toBeGreaterThanOrEqual(0);
174
+ expect(names.indexOf('Calendar')).toBeLessThan(names.indexOf('Scheduler'));
175
+ });
176
+
177
+ it('orders near misses by how many edits away they are', async () => {
178
+ const items = [
179
+ {package: '@acme/charts', kind: 'component', name: 'Paginaters', installed: false},
180
+ {package: '@acme/charts', kind: 'component', name: 'Paginator', installed: false},
181
+ ];
182
+ const res = await search(packages, 'Paginatr', {items});
183
+ const names = res.data.matches.map(m => m.component);
184
+ expect(names.indexOf('Paginator')).toBeLessThan(names.indexOf('Paginaters'));
185
+ });
186
+
187
+ it('a one-edit miss on a longer name returns results', async () => {
188
+ // 'AlpheCard' vs 'AlphaCard' is distance 1, well above 5 chars
189
+ const res = await search(packages, 'AlpheCard', {});
190
+ expect(res.type).toBe('discover.search');
191
+ expect(res.data.matches.map(m => m.component)).toContain('AlphaCard');
192
+ });
193
+
194
+ it('a short word with distance 1 still throws (below min-length guard)', async () => {
195
+ // 'Betz' vs 'Beta' is distance 1, but both are only 4 chars (< 5)
196
+ await expect(search(packages, 'Betz', {})).rejects.toMatchObject({
197
+ code: 'ERR_NOT_FOUND',
198
+ });
199
+ });
200
+
201
+ it('includes catalog items in fuzzy matches too', async () => {
202
+ const items = [
203
+ {package: '@acme/charts', kind: 'component', name: 'Alphabets', installed: false},
204
+ ];
205
+ // 'Alphabel' vs 'Alphabets' is distance 2, both >= 8 chars
206
+ const res = await search(packages, 'Alphabel', {items});
207
+ expect(res.type).toBe('discover.search');
208
+ expect(res.data.matches.map(m => m.component)).toContain('Alphabets');
209
+ });
210
+ });
211
+
145
212
  describe('discover.search leaf across every kind and source', () => {
146
213
  /** @type {any[]} */
147
214
  const items = [