@astryxdesign/cli 0.7.2-canary.52c4239 → 0.7.2-canary.55d8dff

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 (221) hide show
  1. package/README.md +15 -14
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/component/_adapter.d.mts +41 -1
  4. package/api/component/_adapter.mjs +93 -7
  5. package/api/component/component.mjs +22 -5
  6. package/api/component/component.test.mjs +80 -0
  7. package/api/component/integration-export-name.test.mjs +644 -0
  8. package/api/component/list/list.mjs +42 -4
  9. package/api/docs/_adapter.d.mts +11 -0
  10. package/api/docs/_adapter.mjs +244 -1
  11. package/api/docs/integrationDocs.test.mjs +124 -0
  12. package/api/doctor/doctor.mjs +27 -3
  13. package/api/doctor/doctor.test.mjs +43 -0
  14. package/api/doctor/theme-checks.mjs +1 -1
  15. package/api/gap-report/gap-report.mjs +67 -4
  16. package/api/index.d.mts +2 -0
  17. package/api/index.mjs +2 -0
  18. package/api/init/run/run.mjs +2 -2
  19. package/api/integration/_adapter.d.mts +12 -0
  20. package/api/integration/_adapter.mjs +54 -0
  21. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  22. package/api/integration/add-contribution.mjs +8 -4
  23. package/api/integration/add-contribution.test.mjs +4 -2
  24. package/api/integration/authoring-checks.mjs +11 -2
  25. package/api/integration/authoring-checks.test.mjs +39 -0
  26. package/api/integration/authoring-checks.type.d.mts +9 -0
  27. package/api/integration/authoring-checks.type.mjs +14 -1
  28. package/api/integration/check/check.d.mts +96 -0
  29. package/api/integration/check/check.mjs +357 -0
  30. package/api/integration/check/check.test.mjs +489 -0
  31. package/api/integration/integration-check.type.d.mts +118 -0
  32. package/api/integration/integration-check.type.mjs +84 -0
  33. package/api/integration/integrationCheck.doc.d.mts +10 -0
  34. package/api/integration/integrationCheck.doc.mjs +73 -0
  35. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  36. package/api/integration/pack-check.mjs +61 -107
  37. package/api/integration/pack-check.test.mjs +359 -0
  38. package/api/integration/validate-integration.mjs +8 -0
  39. package/api/integration/validate-integration.test.mjs +11 -0
  40. package/api/integration/validate-integration.type.d.mts +8 -0
  41. package/api/integration/validate-integration.type.mjs +12 -1
  42. package/api/integration/validateIntegration.doc.mjs +19 -3
  43. package/api/search/search.d.mts +79 -12
  44. package/api/search/search.domain-priority.test.mjs +108 -18
  45. package/api/search/search.integration-check.test.mjs +24 -0
  46. package/api/search/search.mjs +561 -53
  47. package/api/search/search.test.mjs +164 -0
  48. package/api/swizzle/copy/copy.mjs +28 -14
  49. package/api/theme/build/build.family.test.mjs +64 -0
  50. package/api/theme/build/build.mjs +180 -24
  51. package/api/theme/themeBuild.doc.mjs +4 -4
  52. package/assets/codemods/transforms/next/__tests__/migrate-list-edge-compensation-to-edge.test.mjs +120 -0
  53. package/assets/codemods/transforms/next/index.mjs +11 -1
  54. package/assets/codemods/transforms/next/migrate-list-edge-compensation-to-edge.mjs +198 -0
  55. package/assets/docs/README.md +10 -0
  56. package/assets/docs/author-a-theme.doc.mjs +1 -1
  57. package/assets/docs/getting-started.doc.mjs +3 -3
  58. package/assets/docs/styling-overview.doc.mjs +1 -1
  59. package/assets/docs/theme.doc.dense.mjs +1 -1
  60. package/assets/docs/theme.doc.mjs +1 -1
  61. package/assets/docs/theme.doc.zh.mjs +1 -1
  62. package/assets/docs/tree/add-a-component.doc.mjs +11 -1
  63. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  64. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  65. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  66. package/assets/docs/tree/block-template.doc.mjs +8 -20
  67. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  68. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  69. package/assets/docs/tree/check-your-docs.doc.mjs +51 -5
  70. package/assets/docs/tree/checks.doc.mjs +24 -16
  71. package/assets/docs/tree/codemods.doc.mjs +4 -4
  72. package/assets/docs/tree/component-family.doc.mjs +8 -6
  73. package/assets/docs/tree/component-imports.doc.mjs +10 -2
  74. package/assets/docs/tree/components.doc.mjs +1 -1
  75. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -18
  76. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  77. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  78. package/assets/docs/tree/docs.doc.mjs +3 -3
  79. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  80. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  81. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  82. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  83. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  84. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  85. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  86. package/assets/docs/tree/integrations.doc.mjs +8 -0
  87. package/assets/docs/tree/links.doc.mjs +6 -5
  88. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  89. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  90. package/assets/docs/tree/migration.doc.mjs +0 -1
  91. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  92. package/assets/docs/tree/page-template.doc.mjs +4 -8
  93. package/assets/docs/tree/publishing.doc.mjs +1 -1
  94. package/assets/docs/tree/quick-start.doc.mjs +37 -21
  95. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  96. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  97. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  98. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  99. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  100. package/assets/docs/tree/single-component.doc.mjs +15 -6
  101. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  102. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  103. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  104. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  105. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  106. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  107. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  108. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  109. package/assets/docs/tree/templates.doc.mjs +1 -1
  110. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  111. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  112. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  113. package/assets/docs/tree/troubleshooting.doc.mjs +13 -5
  114. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  115. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  116. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  117. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  118. package/assets/docs/tree/versioning.doc.mjs +7 -6
  119. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  120. package/assets/docs/use-a-theme.doc.mjs +2 -2
  121. package/assets/docs/working-with-ai.doc.mjs +43 -4
  122. package/assets/theme.template.ts +1 -1
  123. package/authoring/codemod/codemod.doc.mjs +7 -3
  124. package/authoring/config/config.doc.mjs +9 -6
  125. package/authoring/config/type.ts +4 -2
  126. package/authoring/discover/discover.doc.mjs +1 -1
  127. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  128. package/authoring/doctypes/command/command.doc.mjs +14 -12
  129. package/authoring/doctypes/component/component.doc.mjs +29 -26
  130. package/authoring/doctypes/component/type.ts +13 -8
  131. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  132. package/authoring/doctypes/function/function.doc.mjs +9 -8
  133. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  134. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  135. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  136. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  137. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  138. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  139. package/authoring/doctypes/template/parse.d.mts +6 -2
  140. package/authoring/doctypes/template/parse.mjs +3 -1
  141. package/authoring/doctypes/template/template.doc.mjs +3 -3
  142. package/authoring/doctypes/template/type.ts +22 -0
  143. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  144. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  145. package/authoring/identity/identity.doc.mjs +3 -3
  146. package/authoring/index.d.ts +1 -0
  147. package/authoring/integration/integration.doc.mjs +12 -4
  148. package/authoring/integration/parse.test.mjs +10 -0
  149. package/authoring/integration/schema.d.mts +2 -0
  150. package/authoring/integration/schema.mjs +1 -0
  151. package/authoring/integration/type.ts +4 -0
  152. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  153. package/clients/cli/commands/build-theme.mjs +1 -1
  154. package/clients/cli/commands/build-theme.path-safety.test.mjs +224 -6
  155. package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
  156. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  157. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  158. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  159. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  160. package/clients/cli/commands/doctor.mjs +190 -0
  161. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  162. package/clients/cli/commands/integration-check.test.mjs +267 -0
  163. package/clients/cli/commands/integration.doc.mjs +6 -2
  164. package/clients/cli/commands/integration.mjs +107 -1
  165. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  166. package/clients/cli/commands/swizzle.mjs +5 -3
  167. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  168. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  169. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  170. package/clients/cli/index.mjs +30 -5
  171. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  172. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  173. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  174. package/foundation/agent-docs/agent-docs.mjs +8 -6
  175. package/foundation/config/project.mjs +82 -0
  176. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  177. package/foundation/discovery/component-discovery.d.mts +190 -10
  178. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  179. package/foundation/discovery/component-discovery.mjs +864 -56
  180. package/foundation/discovery/component-discovery.test.mjs +96 -0
  181. package/foundation/discovery/component-replacement.mjs +18 -0
  182. package/foundation/discovery/component-replacement.test.mjs +40 -0
  183. package/foundation/discovery/doc-types.d.mts +157 -0
  184. package/foundation/discovery/doc-types.mjs +1224 -0
  185. package/foundation/discovery/doc-types.test.mjs +700 -0
  186. package/foundation/discovery/docs-discovery.d.mts +81 -0
  187. package/foundation/discovery/docs-discovery.mjs +57 -0
  188. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  189. package/foundation/discovery/integration-doc-files.mjs +231 -0
  190. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  191. package/foundation/discovery/module-exports.d.mts +27 -0
  192. package/foundation/discovery/module-exports.mjs +356 -31
  193. package/foundation/discovery/module-exports.test.mjs +172 -0
  194. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  195. package/foundation/discovery/package-tsconfig.mjs +228 -0
  196. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  197. package/foundation/discovery/project-typescript.d.mts +32 -0
  198. package/foundation/discovery/project-typescript.mjs +89 -0
  199. package/foundation/discovery/prop-drift.d.mts +278 -0
  200. package/foundation/discovery/prop-drift.mjs +2263 -0
  201. package/foundation/discovery/prop-drift.test.mjs +2272 -0
  202. package/foundation/discovery/type-match.d.mts +53 -0
  203. package/foundation/discovery/type-match.mjs +660 -0
  204. package/foundation/discovery/type-match.test.mjs +169 -0
  205. package/foundation/discovery/type-text.d.mts +68 -0
  206. package/foundation/discovery/type-text.mjs +658 -0
  207. package/foundation/discovery/type-text.test.mjs +196 -0
  208. package/foundation/discovery/unresolved-references.d.mts +62 -0
  209. package/foundation/discovery/unresolved-references.mjs +790 -0
  210. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  211. package/foundation/doc-compiler/doc-loads.test.mjs +14 -0
  212. package/foundation/doc-compiler/inputs.mjs +23 -0
  213. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  214. package/foundation/doc-compiler/links.d.mts +9 -5
  215. package/foundation/doc-compiler/links.mjs +4 -2
  216. package/foundation/integrations/contribution-inventory.mjs +6 -1
  217. package/foundation/response/response-types.doc.mjs +7 -2
  218. package/foundation/xle/registry.mjs +4 -0
  219. package/foundation/xle/registry.test.mjs +28 -0
  220. package/package.json +9 -9
  221. package/scripts/postinstall.mjs +3 -3
@@ -57,9 +57,10 @@
57
57
  * Between domains, ranking adds one rule ahead of the score: domain priority
58
58
  * (see {@link domainPriority}). A component, hook, template, or theme whose
59
59
  * name or keyword a query word hits ranks ahead of every doc the reader did not
60
- * ask for by name or title, so `font size` finds `Text` before a typography
61
- * topic that declares the phrase. A doc the query names, or whose title the
62
- * query holds, keeps its place.
60
+ * ask for by name, title, or a declared phrase, so `font size` finds `Text`
61
+ * before a token page whose heading holds the phrase. A doc the query names,
62
+ * whose title the query holds, or that declares the whole query as a keyword
63
+ * keeps its place.
63
64
  *
64
65
  * Description and guidance are separate tiers on purpose. A component's own
65
66
  * one-line description saying "notification" is a claim about what it IS; the
@@ -81,11 +82,20 @@
81
82
 
82
83
  import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
83
84
  import {readDocView} from '../../foundation/doc-compiler/read.mjs';
84
- import {findCoreDir} from '../../foundation/fs/paths.mjs';
85
+ import {
86
+ discoverExternalPackages,
87
+ findCoreDir,
88
+ } from '../../foundation/fs/paths.mjs';
85
89
  import {
86
90
  discoverComponents,
87
91
  discoverValidIntegrationComponents,
92
+ docStem,
93
+ familyMember,
88
94
  findComponentReadme,
95
+ forEachIntegrationDoc,
96
+ integrationMemberEntry,
97
+ integrationRecordHold,
98
+ isIntegrationMember,
89
99
  resolveImportPath,
90
100
  resolveIntegrationImportPath,
91
101
  CORE_PACKAGE,
@@ -97,6 +107,7 @@ import {
97
107
  import {
98
108
  loadComponentReplacements,
99
109
  loadIntegrationsSafely,
110
+ resolveLegacyExternalDoc,
100
111
  } from '../component/_adapter.mjs';
101
112
  import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
102
113
  import {discoverTemplates, extractComponents} from '../template/template.mjs';
@@ -128,6 +139,9 @@ import {setResultCoverage} from './coverage.mjs';
128
139
  * @property {string[]} [aliases] - Other names the candidate answers to, scored
129
140
  * with the same name signals: a theme's display name.
130
141
  * @property {string[]} [keywords]
142
+ * @property {string[]} [_declared] - A doc's own declared keywords: what its
143
+ * author lists in `keywords`, without the code terms and table cells its
144
+ * other keywords add.
131
145
  * @property {string[]} [weakKeywords]
132
146
  * @property {string} [description]
133
147
  * @property {string[]} [prose]
@@ -149,6 +163,9 @@ import {setResultCoverage} from './coverage.mjs';
149
163
  * @property {'page'|'block'} [_kind]
150
164
  * @property {string} [_resultName]
151
165
  * @property {string} [_commandName]
166
+ * @property {'file'|'doc'} [_hold] - How an integration component holds its
167
+ * name, for the owner rule.
168
+ * @property {string} [_docPath] - An integration component's doc.
152
169
  */
153
170
 
154
171
  /**
@@ -242,9 +259,34 @@ function wordForms(w) {
242
259
  if (w.length > 3 && w.endsWith('s')) forms.add(w.slice(0, -1));
243
260
  if (w.length > 4 && w.endsWith('es')) forms.add(w.slice(0, -2));
244
261
  if (w.length > 4 && w.endsWith('ies')) forms.add(w.slice(0, -3) + 'y');
262
+ // A gerund keeps its verb: "spacing" lost a final e ("space"), and
263
+ // "dragging" doubled a consonant ("drag"). A past participle does not: it
264
+ // usually describes a state ("archived notes"), not the action a catalog
265
+ // word names.
266
+ if (w.length >= 6 && w.endsWith('ing')) {
267
+ const base = w.slice(0, -3);
268
+ forms.add(base);
269
+ forms.add(`${base}e`);
270
+ if (/([b-df-hj-np-tv-z])\1$/.test(base)) forms.add(base.slice(0, -1));
271
+ }
245
272
  return forms;
246
273
  }
247
274
 
275
+ /**
276
+ * The singulars a lowercase word may have when it ends in a plural suffix:
277
+ * "tokens" is "token", "boxes" is "box", "entries" is "entry".
278
+ * @param {string} w
279
+ * @returns {string[]}
280
+ */
281
+ function singulars(w) {
282
+ /** @type {string[]} */
283
+ const out = [];
284
+ if (w.length > 3 && w.endsWith('s')) out.push(w.slice(0, -1));
285
+ if (w.length > 4 && w.endsWith('es')) out.push(w.slice(0, -2));
286
+ if (w.length > 4 && w.endsWith('ies')) out.push(w.slice(0, -3) + 'y');
287
+ return out;
288
+ }
289
+
248
290
  /**
249
291
  * Whether two lowercase words are the same word, up to plural and stem form.
250
292
  * @param {string} a
@@ -285,9 +327,180 @@ function wordsOf(text) {
285
327
  function startsAWordOf(term, text) {
286
328
  if (term.length < 4) return false;
287
329
  if (term.length / String(text).length < 0.5) return false;
288
- return wordsOf(text).some(w => w.startsWith(term) || sameWord(term, w));
330
+ // The term or its singular may start the word: "tokens" starts
331
+ // "tokenizer" through "token". A singular needs five letters, so "stats"
332
+ // does not start "status".
333
+ const starts = [term, ...singulars(term).filter(f => f.length >= 5)];
334
+ return wordsOf(text).some(
335
+ w => starts.some(f => w.startsWith(f)) || sameWord(term, w),
336
+ );
337
+ }
338
+
339
+ /**
340
+ * A query with its camelCase and PascalCase identifiers spelled as words, so
341
+ * `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
342
+ * table pagination state". Plain words, and identifiers joined with `_` or `-`, are
343
+ * unchanged: a joined token that matches nothing stays unmatched.
344
+ * @param {string} query - The query as typed, before lowercasing.
345
+ * @returns {string} Lowercased.
346
+ */
347
+ export function spellIdentifiers(query) {
348
+ return String(query)
349
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
350
+ .replace(/([A-Z])([A-Z][a-z])/g, '$1 $2')
351
+ .toLowerCase();
352
+ }
353
+
354
+ /**
355
+ * A name or keyword with its separators removed, lowercased: `Side Nav`,
356
+ * `side-nav`, and `SideNav` all join to `sidenav`.
357
+ * @param {string} text
358
+ * @returns {string}
359
+ */
360
+ function joined(text) {
361
+ return String(text)
362
+ .toLowerCase()
363
+ .replace(/[^a-z0-9]+/g, '');
364
+ }
365
+
366
+ /**
367
+ * The strongest hit a run of two or more adjacent query words has when it is
368
+ * read as one joined word, and the query words it covers. Readers type a
369
+ * compound name as separate words (`table header cell` is TableHeaderCell,
370
+ * `number field` the keyword `numberfield`), and no single word of the run
371
+ * matches on its own.
372
+ *
373
+ * - 100: the run joins to a component, hook, or template name, or its plural
374
+ * (`table header cells` is TableHeaderCell), or a hook name without its
375
+ * `use` prefix (`table sticky columns` is useTableStickyColumns).
376
+ * - 90: the run joins to a one-word keyword (`number field` is
377
+ * `numberfield`).
378
+ * - 95: the run joins to most of a name, cut short (`dropdown menu radio` is
379
+ * DropdownMenuRadioItem); 92: it is a name's leading words, covering at least half
380
+ * of it (`top nav mega` is TopNavMegaMenu); 70: it is two or more adjacent
381
+ * words of a name that cover at least half of it (`header cell` in
382
+ * TableHeaderCell), the same coverage a word prefix needs. These three
383
+ * are for components and hooks only.
384
+ *
385
+ * A doc's name is a route or key, so docs are left out.
386
+ * @param {string[]} words - The query's words, stopwords included.
387
+ * @param {Candidate} candidate
388
+ * @returns {{score: number, reason: string, covered: Set<string>, alias?: boolean} | null}
389
+ * `covered` holds the run's words and every stretch of them joined. `alias`
390
+ * marks a hit on part of a name or on a keyword, not on the whole name.
391
+ */
392
+ export function compoundHit(words, candidate) {
393
+ if (candidate.domain === 'doc' || words.length < 2) return null;
394
+ const names = [candidate.name, ...(candidate.aliases ?? [])]
395
+ .filter(Boolean)
396
+ .map(name => ({name, nameJoined: joined(name), nameWords: wordsOf(name)}));
397
+ // Part of a name counts only for a component or hook. A template's name
398
+ // starts with the component it shows (`ProgressBarShowcase`), so part of it
399
+ // names the component, not the template.
400
+ const partial =
401
+ candidate.domain === 'component' || candidate.domain === 'hook';
402
+ // One-word lowercase keywords: a keyword an author declares for a reader
403
+ // to type, joined (`numberfield`). A capitalized one names another entry (a
404
+ // block's `componentsUsed`), which matches by its own name, and a keyword of
405
+ // several words is a phrase, matched as one.
406
+ const keywords = (candidate.keywords ?? []).filter(k =>
407
+ /^[a-z0-9]+$/.test(String(k)),
408
+ );
409
+ /** @type {{score: number, reason: string, covered: Set<string>, alias?: boolean} | null} */
410
+ let best = null;
411
+ for (const {run, word} of queryRuns(words)) {
412
+ let score = 0;
413
+ let reason = '';
414
+ for (const {name, nameJoined, nameWords} of names) {
415
+ if (
416
+ nameJoined === word ||
417
+ pluralOf(word, nameJoined) ||
418
+ (candidate.domain === 'hook' && nameJoined === `use${word}`)
419
+ ) {
420
+ if (score < 100) [score, reason] = [100, `name ${name} spelled`];
421
+ } else if (!partial) {
422
+ continue;
423
+ } else if (
424
+ nameJoined.startsWith(word) &&
425
+ word.length / nameJoined.length >= 0.75
426
+ ) {
427
+ // Most of the name, cut short: `dropdown menu radio` is
428
+ // DropdownMenuRadioItem.
429
+ if (score < 95) [score, reason] = [95, `name ${name} spelled`];
430
+ } else if (
431
+ word.length / nameJoined.length >= 0.5 &&
432
+ run.every(
433
+ (w, j) => nameWords[j + (nameWords[0] === 'use' ? 1 : 0)] === w,
434
+ )
435
+ ) {
436
+ // The name's leading words: `top nav mega` is TopNavMegaMenu.
437
+ if (score < 92)
438
+ [score, reason] = [92, `name ${name} starts "${run.join(' ')}"`];
439
+ } else if (
440
+ word.length / nameJoined.length >= 0.5 &&
441
+ nameWords.some((_, k) => run.every((w, j) => nameWords[k + j] === w))
442
+ ) {
443
+ if (score < 70)
444
+ [score, reason] = [70, `name ${name} holds "${run.join(' ')}"`];
445
+ }
446
+ }
447
+ if (score < 90 && keywords.includes(word)) {
448
+ [score, reason] = [90, `keyword "${run.join(' ')}" spelled`];
449
+ }
450
+ if (score > (best?.score ?? 0)) {
451
+ // Each word of the run, and each identifier typed as several of its
452
+ // words joined (`dropdownMenu` in `dropdownMenu checkbox`).
453
+ const covered = new Set();
454
+ for (let a = 0; a < run.length; a++) {
455
+ for (let b = a + 1; b <= run.length; b++) {
456
+ covered.add(run.slice(a, b).join(''));
457
+ }
458
+ }
459
+ best = {score, reason, covered, ...(score < 100 ? {alias: true} : {})};
460
+ }
461
+ }
462
+ return best;
289
463
  }
290
464
 
465
+ /**
466
+ * The longest run of adjacent query words read as one name. Core's longest
467
+ * names run to six words; a longer run is a sentence, not a name, and reading
468
+ * every run of a long build idea costs time on every candidate.
469
+ */
470
+ const MAX_RUN_WORDS = 6;
471
+
472
+ /**
473
+ * Each run of two to {@link MAX_RUN_WORDS} adjacent query words, longest
474
+ * first, with the run joined into one word. Computed once per query.
475
+ * @type {WeakMap<string[], {run: string[], word: string}[]>}
476
+ */
477
+ const runsOf = new WeakMap();
478
+
479
+ /**
480
+ * @param {string[]} words
481
+ * @returns {{run: string[], word: string}[]}
482
+ */
483
+ function queryRuns(words) {
484
+ let runs = runsOf.get(words);
485
+ if (runs) return runs;
486
+ runs = [];
487
+ for (let len = Math.min(words.length, MAX_RUN_WORDS); len >= 2; len--) {
488
+ for (let i = 0; i + len <= words.length; i++) {
489
+ const run = words.slice(i, i + len);
490
+ runs.push({run, word: run.join('')});
491
+ }
492
+ }
493
+ runsOf.set(words, runs);
494
+ return runs;
495
+ }
496
+
497
+ /**
498
+ * Each candidate's compound hit from its last scoreQuery, so domainPriority
499
+ * reads it without walking the query's runs again.
500
+ * @type {WeakMap<object, ReturnType<typeof compoundHit>>}
501
+ */
502
+ const compoundOf = new WeakMap();
503
+
291
504
  /**
292
505
  * The fewest letters both words need before an edit distance counts as a
293
506
  * typo, by distance. Below them, one edit usually makes a different word.
@@ -500,19 +713,20 @@ const STRONG_TOKEN_SCORE = 70;
500
713
  * typography/font-setup, `side panel` is "Side panels");
501
714
  * - 1: a word of the query is the topic's name (`illustration` in a longer
502
715
  * question is the illustrations guide);
716
+ * - 1: a query of two or more words is one of the topic's own declared
717
+ * keywords, whatever the plural (`code review` on a guide that declares it);
503
718
  * - 1: the query holds one of the doc's titles whole (`resizable side panels`
504
719
  * names "Side panels"; `light dark mode button` names "Light/Dark Mode");
505
720
  * - 1: the doc matches every word of the query and one of them is a word of
506
721
  * its title (`switch to a dark theme` and "Use a theme").
507
722
  * A section answers to its topic's name.
508
723
  *
509
- * A doc that matched only by keyword, by a heading holding the query, or by
724
+ * A doc that matched only by a heading holding the query, by one word, or by
510
725
  * words spread through its text has no priority. Docs are split into many
511
- * small topics, and each declares its own keywords and headings, so a common
512
- * phrase such as `font size` hits a guide's keyword or heading exactly
513
- * (170-190) while the component the reader is after matches one word by
514
- * keyword (`Text`, 98). Ranked on text alone, every split adds another doc
515
- * above the component. Broad reference pages match every word of many queries
726
+ * small topics, each with its own headings, so a common phrase such as
727
+ * `font size` hits a heading exactly (170) while the component the reader is
728
+ * after matches one word by keyword (`Text`, 98). Ranked on text alone, every
729
+ * split adds another doc above the component. Broad reference pages match every word of many queries
516
730
  * in their text the same way. The score stays the text-match strength the
517
731
  * result reports, so callers that gate on it (`build`) see the same numbers.
518
732
  *
@@ -523,7 +737,13 @@ const STRONG_TOKEN_SCORE = 70;
523
737
  * candidate's scoreQuery result.
524
738
  * @returns {0 | 1 | 2}
525
739
  */
526
- export function domainPriority(term, tokens, candidate, hit) {
740
+ export function domainPriority(
741
+ term,
742
+ tokens,
743
+ candidate,
744
+ hit,
745
+ queryWords = phraseWords(term),
746
+ ) {
527
747
  const words = [term, ...tokens];
528
748
  if (candidate.domain === 'doc') {
529
749
  const topic = String(candidate._topic ?? candidate.name).toLowerCase();
@@ -538,6 +758,20 @@ export function domainPriority(term, tokens, candidate, hit) {
538
758
  if (named.some(n => samePhrase(term, n))) {
539
759
  return 2;
540
760
  }
761
+ // A query of two or more words that is one of the doc's own declared
762
+ // keywords, read as words whatever the plural, is the author naming the
763
+ // doc for that phrase: `code review` on a guide that declares it. Only
764
+ // what the author declared counts: the code terms and table cells a
765
+ // doc's other keywords add (`missing_field`) name what it mentions, not
766
+ // what it is for. One word is left out too, and a section declares
767
+ // nothing.
768
+ if (
769
+ phraseWords(term).length >= 2 &&
770
+ candidate._section == null &&
771
+ (candidate._declared ?? []).some(k => samePhrase(term, String(k)))
772
+ ) {
773
+ return 1;
774
+ }
541
775
  if (
542
776
  words.some(
543
777
  w =>
@@ -568,6 +802,12 @@ export function domainPriority(term, tokens, candidate, hit) {
568
802
  return 0;
569
803
  }
570
804
  if (hit.score >= FULL_COVERAGE_SCORE) return 1;
805
+ const compound = compoundOf.has(candidate)
806
+ ? compoundOf.get(candidate)
807
+ : compoundHit(queryWords, candidate);
808
+ if ((compound?.score ?? 0) >= STRONG_TOKEN_SCORE) {
809
+ return 1;
810
+ }
571
811
  const fuzzy = tokens.length <= 1;
572
812
  return words.some(
573
813
  w =>
@@ -683,14 +923,24 @@ export function titleInQuery(term, titles) {
683
923
  * @param {string} term - Lowercased full query.
684
924
  * @param {string[]} tokens - Content tokens from tokenizeQuery(term).
685
925
  * @param {Candidate} candidate
686
- * @returns {{score: number, reason: string, matched: number, total: number} | null}
926
+ * @param {string[]} [words] - The query's words for compound names (see
927
+ * compoundHit); empty when the query names an entry outright.
928
+ * @param {{plain?: boolean}} [opts] - `plain`: score without matches on part
929
+ * of a name or a joined keyword.
930
+ * @returns {{score: number, reason: string, matched: number, total: number, alias?: boolean} | null}
687
931
  * `matched`/`total` are the query concepts this candidate answered, out of
688
932
  * the concepts the query had. Callers that must distinguish "matched one word
689
933
  * of three" from "matched all three" — `build`, which gates its pages group
690
934
  * on coverage — cannot recover that from the score, because a single strong
691
935
  * hit and a broad weak one land on the same number.
692
936
  */
693
- export function scoreQuery(term, tokens, candidate) {
937
+ export function scoreQuery(
938
+ term,
939
+ tokens,
940
+ candidate,
941
+ words = phraseWords(term),
942
+ {plain = false} = {},
943
+ ) {
694
944
  const total = Math.max(tokens.length, 1);
695
945
  // A whole-phrase hit answered the whole query by definition.
696
946
  const asFull = (/** @type {{score: number, reason: string}} */ hit) => ({
@@ -699,14 +949,24 @@ export function scoreQuery(term, tokens, candidate) {
699
949
  total,
700
950
  });
701
951
  // Typo tolerance is for one-word lookups. In a multi-word query a near miss
702
- // is usually a different word, not a typo.
703
- const fuzzy = tokens.length <= 1;
704
- const full = scoreCandidate(term, candidate, {fuzzy});
952
+ // is usually a different word, not a typo. One typed identifier is one
953
+ // word, whatever words it spells.
954
+ const fuzzy = tokens.length <= 1 || !/\s/.test(term);
955
+ const full = scoreCandidate(term, candidate, {
956
+ fuzzy,
957
+ joins: !plain && words.length > 0,
958
+ });
705
959
  // A query of several words keeps its phrase tiers below even when stopwords
706
960
  // leave one content word: "make an integration" is still the phrase an
707
961
  // author declares as a keyword, and "build an integration" still names a
708
962
  // title outright, though each tokenizes to `integration` alone.
709
- const phrase = phraseWords(term).length >= 2;
963
+ const phrase = phraseWords(term).length >= 2 || words.length >= 2;
964
+ let compound = compoundHit(words, candidate);
965
+ if (plain) {
966
+ if (compound?.alias) compound = null;
967
+ } else {
968
+ compoundOf.set(candidate, compound);
969
+ }
710
970
 
711
971
  /** 0–1 content tokens: whole-phrase fuzzy matching (typo tolerance for
712
972
  * single words), but if stopwords left exactly one DIFFERENT token (e.g.
@@ -731,7 +991,11 @@ export function scoreQuery(term, tokens, candidate) {
731
991
  // of Table-related templates each match "table" and "contents" separately
732
992
  // and accumulate a higher raw score (#5239).
733
993
  if (full && full.score >= 90) {
734
- return asFull({score: full.score + 100, reason: full.reason});
994
+ return asFull({
995
+ score: full.score + 100,
996
+ reason: full.reason,
997
+ ...(full.alias ? {alias: true} : {}),
998
+ });
735
999
  }
736
1000
 
737
1001
  // The whole query standing as a phrase in a doc's title or one of its
@@ -757,8 +1021,20 @@ export function scoreQuery(term, tokens, candidate) {
757
1021
  let tokenSum = 0;
758
1022
  /** @type {string[]} */
759
1023
  const hitTerms = [];
1024
+ // Adjacent words that join into a name or keyword answer each word they
1025
+ // join, as strongly as the joined word matches (see compoundHit).
1026
+ // Whether a counted word matched only through part of a name or a keyword
1027
+ // read joined, not through the entry's own name or a word of it.
1028
+ let alias = false;
760
1029
  for (const tok of tokens) {
761
- const h = bestForToken(tok, candidate, {fuzzy});
1030
+ let h = bestForToken(tok, candidate, {fuzzy});
1031
+ if (
1032
+ compound?.covered.has(joined(tok)) &&
1033
+ compound.score > (h?.score ?? 0)
1034
+ ) {
1035
+ h = compound;
1036
+ if (compound.alias && compound.score >= MIN_TOKEN_SCORE) alias = true;
1037
+ }
762
1038
  if (h && h.score >= MIN_TOKEN_SCORE) {
763
1039
  if (h.score > strongest) strongest = h.score;
764
1040
  matched++;
@@ -808,6 +1084,7 @@ export function scoreQuery(term, tokens, candidate) {
808
1084
  reason,
809
1085
  matched,
810
1086
  total,
1087
+ ...(alias ? {alias} : {}),
811
1088
  };
812
1089
  }
813
1090
 
@@ -833,7 +1110,7 @@ export function scoreQuery(term, tokens, candidate) {
833
1110
  strongest + Math.min(matched - 1, 3) * 12 + coverage * 15,
834
1111
  );
835
1112
  if (full && full.score >= tokenScore) return asFull(full);
836
- return {score: tokenScore, reason, matched, total};
1113
+ return {score: tokenScore, reason, matched, total, ...(alias ? {alias} : {})};
837
1114
  }
838
1115
 
839
1116
  /**
@@ -852,8 +1129,9 @@ export function scoreQuery(term, tokens, candidate) {
852
1129
  * @param {string} [candidate.description]
853
1130
  * @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
854
1131
  * @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
855
- * @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
856
- * @returns {{score: number, reason: string} | null}
1132
+ * @param {{fuzzy?: boolean, joins?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright.
1133
+ * @returns {{score: number, reason: string, alias?: boolean} | null} `alias`
1134
+ * marks a hit that read the query's words joined.
857
1135
  */
858
1136
  export function scoreCandidate(
859
1137
  term,
@@ -867,18 +1145,21 @@ export function scoreCandidate(
867
1145
  prose = [],
868
1146
  guidance = [],
869
1147
  },
870
- {fuzzy = true} = {},
1148
+ {fuzzy = true, joins = true} = {},
871
1149
  ) {
872
1150
  let best = 0;
873
1151
  let reason = '';
1152
+ let alias = false;
874
1153
  /**
875
1154
  * @param {number} score
876
1155
  * @param {string} why
1156
+ * @param {boolean} [byAlias] - the hit reads the query's words joined
877
1157
  */
878
- const consider = (score, why) => {
1158
+ const consider = (score, why, byAlias = false) => {
879
1159
  if (score > best) {
880
1160
  best = score;
881
1161
  reason = why;
1162
+ alias = byAlias;
882
1163
  }
883
1164
  };
884
1165
 
@@ -902,6 +1183,16 @@ export function scoreCandidate(
902
1183
  nameLower === term.replace(/\s+/g, '');
903
1184
  if (nameLower === term || leafLower === term || spelled) {
904
1185
  consider(100, 'exact name');
1186
+ } else if (
1187
+ joins &&
1188
+ (domain === 'component' || domain === 'hook') &&
1189
+ /\s/.test(term) &&
1190
+ nameLower.startsWith(term.replace(/\s+/g, '')) &&
1191
+ term.replace(/\s+/g, '').length / nameLower.length >= 0.75
1192
+ ) {
1193
+ // Most of the name typed as words, cut short: `complex select` is
1194
+ // ComplexSelector, ahead of a one-word keyword elsewhere.
1195
+ consider(95, `name "${candidateName}" spelled`, true);
905
1196
  } else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
906
1197
  // One point under the exact spelling, so the doc named `tokens` still
907
1198
  // outranks the Token component for `tokens`.
@@ -925,12 +1216,27 @@ export function scoreCandidate(
925
1216
  }
926
1217
 
927
1218
  // ── Keyword signals ─────────────────────────────────────────────
1219
+ const termJoined = joined(term);
928
1220
  for (const kw of keywords) {
929
1221
  const kwLower = String(kw).toLowerCase();
1222
+ // A one-word keyword typed as separate words is the keyword: `number
1223
+ // field` is `numberfield`. Only a
1224
+ // lowercase keyword, one an author declares for a reader to type: a
1225
+ // capitalized one names another entry (a block's `componentsUsed`). A
1226
+ // doc's keywords include code terms, matched as written.
930
1227
  if (kwLower === term) {
931
1228
  consider(90, `keyword "${kw}"`);
932
1229
  continue;
933
1230
  }
1231
+ if (
1232
+ joins &&
1233
+ domain !== 'doc' &&
1234
+ /\s/.test(term) &&
1235
+ String(kw) === termJoined
1236
+ ) {
1237
+ consider(90, `keyword "${kw}"`, true);
1238
+ continue;
1239
+ }
934
1240
  if (sameWord(term, kwLower)) {
935
1241
  consider(88, `keyword "${kw}"`);
936
1242
  continue;
@@ -962,9 +1268,12 @@ export function scoreCandidate(
962
1268
  // Match the term's stem as a whole word, tolerating plural/gerund suffixes
963
1269
  // so "chart" matches "charts" and "filter" matches "filtering".
964
1270
  if (term.length >= 3) {
965
- const root = stem(term);
966
- const escaped = root.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
967
- const re = new RegExp(`\\b${escaped}(s|es|ing|ed|ies)?\\b`);
1271
+ // Any form of the term, with any common suffix: `spacing` finds
1272
+ // "space" and "spaces", `sortable` finds "sorting".
1273
+ const roots = [...new Set([stem(term), ...wordForms(term)])]
1274
+ .filter(f => f.length >= 3)
1275
+ .map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
1276
+ const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
968
1277
  if (description && re.test(description.toLowerCase())) {
969
1278
  consider(50, `description mentions "${term}"`);
970
1279
  } else {
@@ -990,7 +1299,7 @@ export function scoreCandidate(
990
1299
  }
991
1300
  }
992
1301
 
993
- return best > 0 ? {score: best, reason} : null;
1302
+ return best > 0 ? {score: best, reason, ...(alias ? {alias} : {})} : null;
994
1303
  }
995
1304
 
996
1305
  /**
@@ -1079,7 +1388,11 @@ async function gatherCoreComponents(coreDir) {
1079
1388
  /** @type {string[]} */
1080
1389
  let guidance = [];
1081
1390
  if (readme && readme.endsWith('.doc.mjs')) {
1082
- const doc = await loadModuleDoc(readme);
1391
+ const loaded = await loadModuleDoc(readme);
1392
+ // A member documented in its family's doc (VStack in Stack's doc) is
1393
+ // indexed from its own entry: the family's keywords and guidance
1394
+ // describe the family, not the member.
1395
+ const doc = familyMember(loaded, comp) ?? loaded;
1083
1396
  if (doc) {
1084
1397
  keywords = Array.isArray(doc.keywords) ? doc.keywords : [];
1085
1398
  description = doc.usage?.description || doc.description || '';
@@ -1105,20 +1418,57 @@ async function gatherCoreComponents(coreDir) {
1105
1418
  * usage/description from each component's .doc.mjs, same as core. Without
1106
1419
  * this, an integration component is invisible to `search`/`build` even
1107
1420
  * though `component --list`/`component <Name>` already resolve it — the two
1108
- * discovery paths silently disagreed.
1421
+ * discovery paths silently disagreed. Also returns, per name, the docs that
1422
+ * hold it by their file name and the loadable docs that only record it.
1109
1423
  * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
1110
- * @returns {Promise<Candidate[]>}
1424
+ * @returns {Promise<{candidates: Candidate[], fileNamed: Map<string, Set<string>>, documented: Map<string, Set<string>>}>}
1111
1425
  */
1112
1426
  async function gatherIntegrationComponents(loadedIntegrations) {
1113
1427
  /** @type {Candidate[]} */
1114
1428
  const candidates = [];
1429
+ // What the owner rule reads: the docs that hold a name by their file name,
1430
+ // loadable or not and hidden ones too, and the loadable docs that only
1431
+ // record it.
1432
+ /** @type {Map<string, Set<string>>} */
1433
+ const fileNamed = new Map();
1434
+ /** @type {Map<string, Set<string>>} */
1435
+ const documented = new Map();
1436
+ /** @param {Map<string, Set<string>>} map @param {string} name @param {string} docPath */
1437
+ const hold = (map, name, docPath) =>
1438
+ map.set(name, (map.get(name) ?? new Set()).add(docPath));
1115
1439
  for (const integration of loadedIntegrations) {
1116
- const {components} = await discoverValidIntegrationComponents(integration);
1440
+ const {components, discovered} =
1441
+ await discoverValidIntegrationComponents(integration);
1442
+ const renamed = new Set(
1443
+ discovered
1444
+ .filter(rec => integrationRecordHold(rec) === 'doc')
1445
+ .filter(rec => !isIntegrationMember(rec))
1446
+ .map(rec => rec.docPath),
1447
+ );
1448
+ forEachIntegrationDoc(integration.components, (docPath, stem) => {
1449
+ if (!renamed.has(docPath)) hold(fileNamed, stem, docPath);
1450
+ });
1117
1451
  for (const rec of components) {
1118
- const doc = await loadModuleDoc(rec.docPath);
1452
+ const loaded = await loadModuleDoc(rec.docPath);
1453
+ // A family member is indexed from its own entry: the family's keywords
1454
+ // and guidance describe the family.
1455
+ const member = isIntegrationMember(rec);
1456
+ const doc = member ? integrationMemberEntry(loaded, rec) : loaded;
1457
+ // A doc that names another export of its file still answers to the
1458
+ // file's name, as `component <file name>` does.
1459
+ const fileName = docStem(rec.docPath);
1460
+ if (integrationRecordHold(rec) === 'doc') {
1461
+ hold(documented, rec.name, rec.docPath);
1462
+ }
1463
+ if (renamed.has(rec.docPath) && !member) {
1464
+ hold(documented, fileName, rec.docPath);
1465
+ }
1119
1466
  candidates.push({
1120
1467
  domain: 'component',
1121
1468
  name: rec.name,
1469
+ aliases: !member && fileName !== rec.name ? [fileName] : [],
1470
+ _hold: integrationRecordHold(rec),
1471
+ _docPath: rec.docPath,
1122
1472
  keywords: doc && Array.isArray(doc.keywords) ? doc.keywords : [],
1123
1473
  description: doc ? doc.usage?.description || doc.description || '' : '',
1124
1474
  guidance: guidanceFrom(doc),
@@ -1138,12 +1488,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1138
1488
  packageName: rec.package,
1139
1489
  },
1140
1490
  rec.name,
1141
- doc?.import,
1491
+ loaded?.import,
1142
1492
  ),
1143
1493
  });
1144
1494
  }
1145
1495
  }
1146
- return candidates;
1496
+ return {candidates, fileNamed, documented};
1147
1497
  }
1148
1498
 
1149
1499
  /**
@@ -1155,11 +1505,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1155
1505
  */
1156
1506
  async function gatherComponents(coreDir, cwd) {
1157
1507
  const loadedIntegrations = await loadIntegrationsSafely(cwd);
1158
- const [core, integrations, replacements] = await Promise.all([
1508
+ const [core, gathered, replacements] = await Promise.all([
1159
1509
  gatherCoreComponents(coreDir),
1160
1510
  gatherIntegrationComponents(loadedIntegrations),
1161
1511
  loadComponentReplacements(coreDir, loadedIntegrations),
1162
1512
  ]);
1513
+ const {candidates: integrations, fileNamed, documented} = gathered;
1163
1514
  // An active replacement answers to the Core name it replaces, so a search
1164
1515
  // for that name finds the replacement and not the Core original
1165
1516
  // (spec:AST-035 FR11).
@@ -1170,9 +1521,43 @@ async function gatherComponents(coreDir, cwd) {
1170
1521
  active.target,
1171
1522
  ]),
1172
1523
  );
1524
+ // The owner rule, as component detail applies it: a candidate `component
1525
+ // <name>` does not open names its package and follows the owner, and a
1526
+ // file-name alias that opens another owner is dropped.
1527
+ const coreNames = new Set(core.map(candidate => candidate.name));
1528
+ /** @param {string} name @param {Candidate} candidate */
1529
+ const opens = (name, candidate) =>
1530
+ !coreNames.has(name) &&
1531
+ findComponentReadme(coreDir, name) == null &&
1532
+ [...(fileNamed.get(name) ?? [])].every(doc => doc === candidate._docPath) &&
1533
+ [...(documented.get(name) ?? [])].every(doc => doc === candidate._docPath);
1534
+ // A legacy docs package keeps an exact name over an export name a doc records.
1535
+ /** @type {ReturnType<typeof discoverExternalPackages> | undefined} */
1536
+ let externals;
1537
+ /** @param {string} name */
1538
+ const legacyDocuments = name =>
1539
+ (externals ??= discoverExternalPackages(cwd)).some(
1540
+ ext => resolveLegacyExternalDoc(ext, name) != null,
1541
+ );
1542
+ const ruled = integrations.map(candidate => {
1543
+ const aliases = (candidate.aliases ?? []).filter(alias =>
1544
+ opens(alias, candidate),
1545
+ );
1546
+ return candidate._hold === 'doc' &&
1547
+ (!opens(candidate.name, candidate) || legacyDocuments(candidate.name))
1548
+ ? {
1549
+ ...candidate,
1550
+ aliases,
1551
+ _command: `astryx component ${candidate.name} --package ${candidate._package}`,
1552
+ }
1553
+ : {...candidate, aliases};
1554
+ });
1173
1555
  return [
1174
1556
  ...core.filter(candidate => !replacements.forTarget(candidate.name)),
1175
- ...integrations.map(candidate => {
1557
+ ...[
1558
+ ...ruled.filter(candidate => !candidate._command),
1559
+ ...ruled.filter(candidate => candidate._command),
1560
+ ].map(candidate => {
1176
1561
  const target = targetOf.get(`${candidate._package}\0${candidate.name}`);
1177
1562
  if (target != null) {
1178
1563
  return {...candidate, aliases: [...(candidate.aliases ?? []), target]};
@@ -1225,11 +1610,11 @@ export async function componentKeywords(coreDir, cwd) {
1225
1610
  .flat()
1226
1611
  .map(async name => {
1227
1612
  const readme = findComponentReadme(coreDir, name);
1228
- const doc =
1613
+ const loaded =
1229
1614
  readme && readme.endsWith('.doc.mjs')
1230
1615
  ? await loadModuleDoc(readme)
1231
1616
  : null;
1232
- return {name, keywords: keywordsOf(doc)};
1617
+ return {name, keywords: keywordsOf(familyMember(loaded, name) ?? loaded)};
1233
1618
  });
1234
1619
  const loadedIntegrations = await loadIntegrationsSafely(cwd);
1235
1620
  const replacements = await loadComponentReplacements(
@@ -1239,10 +1624,13 @@ export async function componentKeywords(coreDir, cwd) {
1239
1624
  const integrations = loadedIntegrations.map(async integration => {
1240
1625
  const {components} = await discoverValidIntegrationComponents(integration);
1241
1626
  return Promise.all(
1242
- components.map(async rec => ({
1243
- name: rec.name,
1244
- keywords: keywordsOf(await loadModuleDoc(rec.docPath)),
1245
- })),
1627
+ components.map(async rec => {
1628
+ const loaded = await loadModuleDoc(rec.docPath);
1629
+ return {
1630
+ name: rec.name,
1631
+ keywords: keywordsOf(integrationMemberEntry(loaded, rec) ?? loaded),
1632
+ };
1633
+ }),
1246
1634
  );
1247
1635
  });
1248
1636
  return [
@@ -1416,6 +1804,10 @@ async function gatherDocs(cwd) {
1416
1804
  ...defined,
1417
1805
  ...codeTerms({content}),
1418
1806
  ],
1807
+ _declared: [
1808
+ ...(Array.isArray(selfDoc?.keywords) ? selfDoc.keywords : []),
1809
+ ...(Array.isArray(node.keywords) ? node.keywords : []),
1810
+ ],
1419
1811
  description: node.summary || '',
1420
1812
  prose: sectionProse({title: node.title, content}),
1421
1813
  titles: [node.title],
@@ -1552,6 +1944,7 @@ function topicCandidates(
1552
1944
  ...(doc?.title || title ? [doc?.title || title] : []),
1553
1945
  ...(Array.isArray(doc?.keywords) ? doc.keywords : []),
1554
1946
  ],
1947
+ _declared: Array.isArray(doc?.keywords) ? doc.keywords : [],
1555
1948
  description: doc?.description || summary,
1556
1949
  prose: split
1557
1950
  ? sections.map(section => section.title).filter(Boolean)
@@ -1811,8 +2204,6 @@ async function searchOnce(query, options) {
1811
2204
  }
1812
2205
 
1813
2206
  const term = String(query).trim().toLowerCase();
1814
- const tokens = tokenizeQuery(term);
1815
-
1816
2207
  // `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
1817
2208
  // list` reads themes without it (bundled themes need no project), so a
1818
2209
  // search of either must too. Every other domain reads core: asked for by
@@ -1844,14 +2235,97 @@ async function searchOnce(query, options) {
1844
2235
 
1845
2236
  const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
1846
2237
 
2238
+ // A query that is one identifier counts as the words it spells
2239
+ // (`SidebarToggle`), and still matches whole as typed. In a query of several
2240
+ // words, each identifier stays one term (`ChatComposer ChatLayout` names two
2241
+ // components), and its words still join into names (see compoundHit). Both
2242
+ // only help a query that names no entry outright: when the query is an
2243
+ // entry's name, typed whole or as its words, that entry answers it, and
2244
+ // neither reading may add near siblings beside it.
2245
+ const spelled = spellIdentifiers(String(query).trim());
2246
+ const exact = all.some(candidate =>
2247
+ [candidate.name, ...(candidate.aliases ?? [])].some(name => {
2248
+ const lower = String(name).toLowerCase();
2249
+ return (
2250
+ lower === term ||
2251
+ (candidate.domain !== 'doc' &&
2252
+ !/[\s_-]/.test(lower) &&
2253
+ lower === term.replace(/\s+/g, ''))
2254
+ );
2255
+ }),
2256
+ );
2257
+ // One identifier is read as its words only when, read whole, it matches
2258
+ // nothing: a prop or hook name a doc already mentions keeps the
2259
+ // entries that mention it.
2260
+ const split =
2261
+ !exact &&
2262
+ !/\s/.test(term) &&
2263
+ spelled !== term &&
2264
+ !all.some(candidate => scoreCandidate(term, candidate));
2265
+ const tokens = tokenizeQuery(split ? spelled : term);
2266
+ /** @type {string[]} */
2267
+ const words = exact
2268
+ ? []
2269
+ : phraseWords(split || /\s/.test(term) ? spelled : term);
2270
+ // The entries the query names: a component, hook, or template whose whole
2271
+ // name is adjacent query words joined (`icon button in a card header` names
2272
+ // IconButton), or one identifier typed as such. A name inside a longer named
2273
+ // run does not count (`icon` there is part of IconButton).
2274
+ const queryWords = phraseWords(spelled);
2275
+ const typedIdentifiers = new Set(
2276
+ (String(query).match(/[A-Za-z0-9]+/g) ?? [])
2277
+ .filter(w => /[A-Z]/.test(w))
2278
+ .map(w => w.toLowerCase()),
2279
+ );
2280
+ /** @type {Map<string, [number, number]>} each run joined, longest first */
2281
+ const spans = new Map();
2282
+ for (let len = Math.min(queryWords.length, MAX_RUN_WORDS); len >= 1; len--) {
2283
+ for (let a = 0; a + len <= queryWords.length; a++) {
2284
+ // One plain word names too much (`list`, `field`); a named entry is a
2285
+ // run of joined words, or an identifier typed as one.
2286
+ if (len === 1 && !typedIdentifiers.has(queryWords[a])) continue;
2287
+ const run = queryWords.slice(a, a + len).join('');
2288
+ if (!spans.has(run)) spans.set(run, [a, a + len]);
2289
+ }
2290
+ }
2291
+ const plainWords = new Set(queryWords);
2292
+ /**
2293
+ * Whether a query word is the candidate's whole name: such an entry keeps
2294
+ * the rank its name earns, whatever else it matched.
2295
+ * @param {Candidate} candidate
2296
+ */
2297
+ const wordNamed = candidate =>
2298
+ candidate.domain !== 'doc' &&
2299
+ [candidate.name, ...(candidate.aliases ?? [])].some(name => {
2300
+ const n = joined(name);
2301
+ return plainWords.has(n) || plainWords.has(`${n}s`);
2302
+ });
2303
+ /** @param {Candidate} candidate @returns {[number, number] | null} */
2304
+ const namedSpan = candidate => {
2305
+ if (candidate.domain === 'doc') return null;
2306
+ /** @type {[number, number] | null} */
2307
+ let best = null;
2308
+ for (const name of [candidate.name, ...(candidate.aliases ?? [])]) {
2309
+ const n = joined(name);
2310
+ const span =
2311
+ spans.get(n) ??
2312
+ spans.get(`${n}s`) ??
2313
+ (/(?:s|x|z|ch|sh)$/.test(n) ? spans.get(`${n}es`) : undefined);
2314
+ if (span && (!best || span[1] - span[0] > best[1] - best[0])) {
2315
+ best = span;
2316
+ }
2317
+ }
2318
+ return best;
2319
+ };
2320
+
1847
2321
  // Score every candidate on its own merits. The consumer groups results by
1848
2322
  // role (page / block / component) and takes the top of each, so there's no
1849
2323
  // cross-role competition to engineer — a target page only needs to be the
1850
2324
  // strongest PAGE, not outrank every component.
1851
- /** @type {{result: any, priority: 0 | 1 | 2}[]} */
2325
+ /** @type {{result: any, priority: 0 | 1 | 2, key: number, alias: boolean, candidate: Candidate, span: [number, number] | null, word: boolean}[]} */
1852
2326
  const ranked = [];
1853
2327
  for (const candidate of all) {
1854
- const hit = scoreQuery(term, tokens, candidate);
2328
+ const hit = scoreQuery(term, tokens, candidate, words);
1855
2329
  if (hit)
1856
2330
  ranked.push({
1857
2331
  result: toResult(
@@ -1861,9 +2335,43 @@ async function searchOnce(query, options) {
1861
2335
  hit.matched,
1862
2336
  hit.total,
1863
2337
  ),
1864
- priority: domainPriority(term, tokens, candidate, hit),
2338
+ priority: domainPriority(term, tokens, candidate, hit, words),
2339
+ key: hit.score,
2340
+ alias: hit.alias === true,
2341
+ candidate,
2342
+ span: namedSpan(candidate),
2343
+ word: wordNamed(candidate),
1865
2344
  });
1866
2345
  }
2346
+ // A match through part of a name or a keyword read joined never outranks
2347
+ // an entry the query names: `table header with sticky columns` keeps
2348
+ // TableHeader above useTableStickyColumns, which only holds the words
2349
+ // `sticky columns`. Only the order changes; each result keeps the score its
2350
+ // text earned.
2351
+ /** @param {[number, number]} inner @param {[number, number]} outer */
2352
+ const inside = (inner, outer) =>
2353
+ outer[0] <= inner[0] &&
2354
+ outer[1] >= inner[1] &&
2355
+ outer[1] - outer[0] > inner[1] - inner[0];
2356
+ const named = ranked.filter(r => {
2357
+ const span = r.span;
2358
+ return (
2359
+ span != null &&
2360
+ !ranked.some(o => o !== r && o.span != null && inside(span, o.span))
2361
+ );
2362
+ });
2363
+ if (named.length > 0) {
2364
+ const floor = Math.min(...named.map(r => r.key));
2365
+ for (const r of ranked) {
2366
+ if (r.alias && !named.includes(r) && !r.word) {
2367
+ // It keeps what it earns without those matches.
2368
+ const own =
2369
+ scoreQuery(term, tokens, r.candidate, words, {plain: true})?.score ??
2370
+ 0;
2371
+ r.key = Math.max(own, Math.min(r.key, floor - 0.5));
2372
+ }
2373
+ }
2374
+ }
1867
2375
 
1868
2376
  // Docs and everything else are each sorted by score desc, then domain
1869
2377
  // (stable order), then name. The two are merged: at each step the stronger
@@ -1872,11 +2380,11 @@ async function searchOnce(query, options) {
1872
2380
  /** @type {Record<string, number>} */
1873
2381
  const domainOrder = {component: 0, hook: 1, doc: 2, template: 3, theme: 4};
1874
2382
  /**
1875
- * @param {{result: any}} x
1876
- * @param {{result: any}} y
2383
+ * @param {{result: any, key: number}} x
2384
+ * @param {{result: any, key: number}} y
1877
2385
  */
1878
- const byScore = ({result: a}, {result: b}) =>
1879
- b.score - a.score ||
2386
+ const byScore = ({result: a, key: ka}, {result: b, key: kb}) =>
2387
+ kb - ka ||
1880
2388
  (domainOrder[a.domain] ?? 9) - (domainOrder[b.domain] ?? 9) ||
1881
2389
  a.name.localeCompare(b.name);
1882
2390
  const others = ranked.filter(r => r.result.domain !== 'doc').sort(byScore);