@astryxdesign/cli 0.7.2-canary.52c26fb → 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 (209) 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/integration-export-name.test.mjs +644 -0
  7. package/api/docs/_adapter.d.mts +11 -0
  8. package/api/docs/_adapter.mjs +244 -1
  9. package/api/docs/integrationDocs.test.mjs +124 -0
  10. package/api/doctor/doctor.mjs +27 -3
  11. package/api/doctor/doctor.test.mjs +43 -0
  12. package/api/doctor/theme-checks.mjs +1 -1
  13. package/api/gap-report/gap-report.mjs +67 -4
  14. package/api/index.d.mts +2 -0
  15. package/api/index.mjs +2 -0
  16. package/api/init/run/run.mjs +2 -2
  17. package/api/integration/_adapter.d.mts +12 -0
  18. package/api/integration/_adapter.mjs +54 -0
  19. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  20. package/api/integration/add-contribution.mjs +8 -4
  21. package/api/integration/add-contribution.test.mjs +4 -2
  22. package/api/integration/authoring-checks.mjs +11 -2
  23. package/api/integration/authoring-checks.test.mjs +39 -0
  24. package/api/integration/authoring-checks.type.d.mts +9 -0
  25. package/api/integration/authoring-checks.type.mjs +14 -1
  26. package/api/integration/check/check.d.mts +96 -0
  27. package/api/integration/check/check.mjs +357 -0
  28. package/api/integration/check/check.test.mjs +489 -0
  29. package/api/integration/integration-check.type.d.mts +118 -0
  30. package/api/integration/integration-check.type.mjs +84 -0
  31. package/api/integration/integrationCheck.doc.d.mts +10 -0
  32. package/api/integration/integrationCheck.doc.mjs +73 -0
  33. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  34. package/api/integration/pack-check.mjs +51 -97
  35. package/api/integration/pack-check.test.mjs +359 -0
  36. package/api/integration/validate-integration.mjs +8 -0
  37. package/api/integration/validate-integration.test.mjs +11 -0
  38. package/api/integration/validate-integration.type.d.mts +8 -0
  39. package/api/integration/validate-integration.type.mjs +12 -1
  40. package/api/integration/validateIntegration.doc.mjs +19 -3
  41. package/api/search/search.d.mts +79 -12
  42. package/api/search/search.domain-priority.test.mjs +108 -18
  43. package/api/search/search.integration-check.test.mjs +24 -0
  44. package/api/search/search.mjs +553 -50
  45. package/api/search/search.test.mjs +128 -0
  46. package/api/swizzle/copy/copy.mjs +28 -14
  47. package/api/theme/build/build.family.test.mjs +54 -6
  48. package/api/theme/build/build.mjs +114 -17
  49. package/api/theme/themeBuild.doc.mjs +4 -4
  50. package/assets/docs/README.md +10 -0
  51. package/assets/docs/author-a-theme.doc.mjs +1 -1
  52. package/assets/docs/getting-started.doc.mjs +3 -3
  53. package/assets/docs/styling-overview.doc.mjs +1 -1
  54. package/assets/docs/theme.doc.dense.mjs +1 -1
  55. package/assets/docs/theme.doc.mjs +1 -1
  56. package/assets/docs/theme.doc.zh.mjs +1 -1
  57. package/assets/docs/tree/add-a-component.doc.mjs +11 -1
  58. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  59. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  60. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  61. package/assets/docs/tree/block-template.doc.mjs +8 -20
  62. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  63. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  64. package/assets/docs/tree/check-your-docs.doc.mjs +51 -5
  65. package/assets/docs/tree/checks.doc.mjs +24 -16
  66. package/assets/docs/tree/codemods.doc.mjs +4 -4
  67. package/assets/docs/tree/component-family.doc.mjs +8 -6
  68. package/assets/docs/tree/component-imports.doc.mjs +10 -2
  69. package/assets/docs/tree/components.doc.mjs +1 -1
  70. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -18
  71. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  72. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  73. package/assets/docs/tree/docs.doc.mjs +3 -3
  74. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  75. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  76. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  77. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  78. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  79. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  80. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  81. package/assets/docs/tree/integrations.doc.mjs +8 -0
  82. package/assets/docs/tree/links.doc.mjs +6 -5
  83. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  84. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  85. package/assets/docs/tree/migration.doc.mjs +0 -1
  86. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  87. package/assets/docs/tree/page-template.doc.mjs +4 -8
  88. package/assets/docs/tree/publishing.doc.mjs +1 -1
  89. package/assets/docs/tree/quick-start.doc.mjs +37 -21
  90. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  91. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  92. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  93. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  94. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  95. package/assets/docs/tree/single-component.doc.mjs +15 -6
  96. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  97. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  98. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  99. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  100. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  101. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  102. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  103. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  104. package/assets/docs/tree/templates.doc.mjs +1 -1
  105. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  106. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  107. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  108. package/assets/docs/tree/troubleshooting.doc.mjs +13 -5
  109. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  110. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  111. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  112. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  113. package/assets/docs/tree/versioning.doc.mjs +7 -6
  114. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  115. package/assets/docs/use-a-theme.doc.mjs +2 -2
  116. package/assets/theme.template.ts +1 -1
  117. package/authoring/codemod/codemod.doc.mjs +7 -3
  118. package/authoring/config/config.doc.mjs +9 -6
  119. package/authoring/config/type.ts +4 -2
  120. package/authoring/discover/discover.doc.mjs +1 -1
  121. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  122. package/authoring/doctypes/command/command.doc.mjs +14 -12
  123. package/authoring/doctypes/component/component.doc.mjs +29 -26
  124. package/authoring/doctypes/component/type.ts +13 -8
  125. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  126. package/authoring/doctypes/function/function.doc.mjs +9 -8
  127. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  128. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  129. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  130. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  131. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  132. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  133. package/authoring/doctypes/template/parse.d.mts +6 -2
  134. package/authoring/doctypes/template/parse.mjs +3 -1
  135. package/authoring/doctypes/template/template.doc.mjs +3 -3
  136. package/authoring/doctypes/template/type.ts +22 -0
  137. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  138. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  139. package/authoring/identity/identity.doc.mjs +3 -3
  140. package/authoring/index.d.ts +1 -0
  141. package/authoring/integration/integration.doc.mjs +12 -4
  142. package/authoring/integration/parse.test.mjs +10 -0
  143. package/authoring/integration/schema.d.mts +2 -0
  144. package/authoring/integration/schema.mjs +1 -0
  145. package/authoring/integration/type.ts +4 -0
  146. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  147. package/clients/cli/commands/build-theme.mjs +1 -1
  148. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  149. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  150. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  151. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  152. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  153. package/clients/cli/commands/doctor.mjs +190 -0
  154. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  155. package/clients/cli/commands/integration-check.test.mjs +267 -0
  156. package/clients/cli/commands/integration.doc.mjs +6 -2
  157. package/clients/cli/commands/integration.mjs +107 -1
  158. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  159. package/clients/cli/commands/swizzle.mjs +5 -3
  160. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  161. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  162. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  163. package/clients/cli/index.mjs +30 -5
  164. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  165. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  166. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  167. package/foundation/agent-docs/agent-docs.mjs +8 -6
  168. package/foundation/config/project.mjs +82 -0
  169. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  170. package/foundation/discovery/component-discovery.d.mts +178 -10
  171. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  172. package/foundation/discovery/component-discovery.mjs +659 -62
  173. package/foundation/discovery/component-replacement.mjs +18 -0
  174. package/foundation/discovery/component-replacement.test.mjs +40 -0
  175. package/foundation/discovery/doc-types.d.mts +157 -0
  176. package/foundation/discovery/doc-types.mjs +1224 -0
  177. package/foundation/discovery/doc-types.test.mjs +700 -0
  178. package/foundation/discovery/docs-discovery.d.mts +81 -0
  179. package/foundation/discovery/docs-discovery.mjs +57 -0
  180. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  181. package/foundation/discovery/integration-doc-files.mjs +231 -0
  182. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  183. package/foundation/discovery/module-exports.d.mts +27 -0
  184. package/foundation/discovery/module-exports.mjs +356 -31
  185. package/foundation/discovery/module-exports.test.mjs +172 -0
  186. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  187. package/foundation/discovery/package-tsconfig.mjs +228 -0
  188. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  189. package/foundation/discovery/project-typescript.d.mts +32 -0
  190. package/foundation/discovery/project-typescript.mjs +89 -0
  191. package/foundation/discovery/prop-drift.d.mts +278 -0
  192. package/foundation/discovery/prop-drift.mjs +2263 -0
  193. package/foundation/discovery/prop-drift.test.mjs +2272 -0
  194. package/foundation/discovery/type-match.d.mts +53 -0
  195. package/foundation/discovery/type-match.mjs +660 -0
  196. package/foundation/discovery/type-match.test.mjs +169 -0
  197. package/foundation/discovery/type-text.d.mts +68 -0
  198. package/foundation/discovery/type-text.mjs +658 -0
  199. package/foundation/discovery/type-text.test.mjs +196 -0
  200. package/foundation/discovery/unresolved-references.d.mts +62 -0
  201. package/foundation/discovery/unresolved-references.mjs +790 -0
  202. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  203. package/foundation/doc-compiler/doc-loads.test.mjs +10 -0
  204. package/foundation/doc-compiler/links.d.mts +9 -5
  205. package/foundation/doc-compiler/links.mjs +4 -2
  206. package/foundation/integrations/contribution-inventory.mjs +6 -1
  207. package/foundation/response/response-types.doc.mjs +7 -2
  208. package/package.json +9 -9
  209. 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,12 +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,
88
93
  familyMember,
89
94
  findComponentReadme,
95
+ forEachIntegrationDoc,
96
+ integrationMemberEntry,
97
+ integrationRecordHold,
98
+ isIntegrationMember,
90
99
  resolveImportPath,
91
100
  resolveIntegrationImportPath,
92
101
  CORE_PACKAGE,
@@ -98,6 +107,7 @@ import {
98
107
  import {
99
108
  loadComponentReplacements,
100
109
  loadIntegrationsSafely,
110
+ resolveLegacyExternalDoc,
101
111
  } from '../component/_adapter.mjs';
102
112
  import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
103
113
  import {discoverTemplates, extractComponents} from '../template/template.mjs';
@@ -129,6 +139,9 @@ import {setResultCoverage} from './coverage.mjs';
129
139
  * @property {string[]} [aliases] - Other names the candidate answers to, scored
130
140
  * with the same name signals: a theme's display name.
131
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.
132
145
  * @property {string[]} [weakKeywords]
133
146
  * @property {string} [description]
134
147
  * @property {string[]} [prose]
@@ -150,6 +163,9 @@ import {setResultCoverage} from './coverage.mjs';
150
163
  * @property {'page'|'block'} [_kind]
151
164
  * @property {string} [_resultName]
152
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.
153
169
  */
154
170
 
155
171
  /**
@@ -243,9 +259,34 @@ function wordForms(w) {
243
259
  if (w.length > 3 && w.endsWith('s')) forms.add(w.slice(0, -1));
244
260
  if (w.length > 4 && w.endsWith('es')) forms.add(w.slice(0, -2));
245
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
+ }
246
272
  return forms;
247
273
  }
248
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
+
249
290
  /**
250
291
  * Whether two lowercase words are the same word, up to plural and stem form.
251
292
  * @param {string} a
@@ -286,9 +327,180 @@ function wordsOf(text) {
286
327
  function startsAWordOf(term, text) {
287
328
  if (term.length < 4) return false;
288
329
  if (term.length / String(text).length < 0.5) return false;
289
- 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;
290
463
  }
291
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
+
292
504
  /**
293
505
  * The fewest letters both words need before an edit distance counts as a
294
506
  * typo, by distance. Below them, one edit usually makes a different word.
@@ -501,19 +713,20 @@ const STRONG_TOKEN_SCORE = 70;
501
713
  * typography/font-setup, `side panel` is "Side panels");
502
714
  * - 1: a word of the query is the topic's name (`illustration` in a longer
503
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);
504
718
  * - 1: the query holds one of the doc's titles whole (`resizable side panels`
505
719
  * names "Side panels"; `light dark mode button` names "Light/Dark Mode");
506
720
  * - 1: the doc matches every word of the query and one of them is a word of
507
721
  * its title (`switch to a dark theme` and "Use a theme").
508
722
  * A section answers to its topic's name.
509
723
  *
510
- * 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
511
725
  * words spread through its text has no priority. Docs are split into many
512
- * small topics, and each declares its own keywords and headings, so a common
513
- * phrase such as `font size` hits a guide's keyword or heading exactly
514
- * (170-190) while the component the reader is after matches one word by
515
- * keyword (`Text`, 98). Ranked on text alone, every split adds another doc
516
- * 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
517
730
  * in their text the same way. The score stays the text-match strength the
518
731
  * result reports, so callers that gate on it (`build`) see the same numbers.
519
732
  *
@@ -524,7 +737,13 @@ const STRONG_TOKEN_SCORE = 70;
524
737
  * candidate's scoreQuery result.
525
738
  * @returns {0 | 1 | 2}
526
739
  */
527
- export function domainPriority(term, tokens, candidate, hit) {
740
+ export function domainPriority(
741
+ term,
742
+ tokens,
743
+ candidate,
744
+ hit,
745
+ queryWords = phraseWords(term),
746
+ ) {
528
747
  const words = [term, ...tokens];
529
748
  if (candidate.domain === 'doc') {
530
749
  const topic = String(candidate._topic ?? candidate.name).toLowerCase();
@@ -539,6 +758,20 @@ export function domainPriority(term, tokens, candidate, hit) {
539
758
  if (named.some(n => samePhrase(term, n))) {
540
759
  return 2;
541
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
+ }
542
775
  if (
543
776
  words.some(
544
777
  w =>
@@ -569,6 +802,12 @@ export function domainPriority(term, tokens, candidate, hit) {
569
802
  return 0;
570
803
  }
571
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
+ }
572
811
  const fuzzy = tokens.length <= 1;
573
812
  return words.some(
574
813
  w =>
@@ -684,14 +923,24 @@ export function titleInQuery(term, titles) {
684
923
  * @param {string} term - Lowercased full query.
685
924
  * @param {string[]} tokens - Content tokens from tokenizeQuery(term).
686
925
  * @param {Candidate} candidate
687
- * @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}
688
931
  * `matched`/`total` are the query concepts this candidate answered, out of
689
932
  * the concepts the query had. Callers that must distinguish "matched one word
690
933
  * of three" from "matched all three" — `build`, which gates its pages group
691
934
  * on coverage — cannot recover that from the score, because a single strong
692
935
  * hit and a broad weak one land on the same number.
693
936
  */
694
- export function scoreQuery(term, tokens, candidate) {
937
+ export function scoreQuery(
938
+ term,
939
+ tokens,
940
+ candidate,
941
+ words = phraseWords(term),
942
+ {plain = false} = {},
943
+ ) {
695
944
  const total = Math.max(tokens.length, 1);
696
945
  // A whole-phrase hit answered the whole query by definition.
697
946
  const asFull = (/** @type {{score: number, reason: string}} */ hit) => ({
@@ -700,14 +949,24 @@ export function scoreQuery(term, tokens, candidate) {
700
949
  total,
701
950
  });
702
951
  // Typo tolerance is for one-word lookups. In a multi-word query a near miss
703
- // is usually a different word, not a typo.
704
- const fuzzy = tokens.length <= 1;
705
- 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
+ });
706
959
  // A query of several words keeps its phrase tiers below even when stopwords
707
960
  // leave one content word: "make an integration" is still the phrase an
708
961
  // author declares as a keyword, and "build an integration" still names a
709
962
  // title outright, though each tokenizes to `integration` alone.
710
- 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
+ }
711
970
 
712
971
  /** 0–1 content tokens: whole-phrase fuzzy matching (typo tolerance for
713
972
  * single words), but if stopwords left exactly one DIFFERENT token (e.g.
@@ -732,7 +991,11 @@ export function scoreQuery(term, tokens, candidate) {
732
991
  // of Table-related templates each match "table" and "contents" separately
733
992
  // and accumulate a higher raw score (#5239).
734
993
  if (full && full.score >= 90) {
735
- 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
+ });
736
999
  }
737
1000
 
738
1001
  // The whole query standing as a phrase in a doc's title or one of its
@@ -758,8 +1021,20 @@ export function scoreQuery(term, tokens, candidate) {
758
1021
  let tokenSum = 0;
759
1022
  /** @type {string[]} */
760
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;
761
1029
  for (const tok of tokens) {
762
- 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
+ }
763
1038
  if (h && h.score >= MIN_TOKEN_SCORE) {
764
1039
  if (h.score > strongest) strongest = h.score;
765
1040
  matched++;
@@ -809,6 +1084,7 @@ export function scoreQuery(term, tokens, candidate) {
809
1084
  reason,
810
1085
  matched,
811
1086
  total,
1087
+ ...(alias ? {alias} : {}),
812
1088
  };
813
1089
  }
814
1090
 
@@ -834,7 +1110,7 @@ export function scoreQuery(term, tokens, candidate) {
834
1110
  strongest + Math.min(matched - 1, 3) * 12 + coverage * 15,
835
1111
  );
836
1112
  if (full && full.score >= tokenScore) return asFull(full);
837
- return {score: tokenScore, reason, matched, total};
1113
+ return {score: tokenScore, reason, matched, total, ...(alias ? {alias} : {})};
838
1114
  }
839
1115
 
840
1116
  /**
@@ -853,8 +1129,9 @@ export function scoreQuery(term, tokens, candidate) {
853
1129
  * @param {string} [candidate.description]
854
1130
  * @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
855
1131
  * @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
856
- * @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
857
- * @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.
858
1135
  */
859
1136
  export function scoreCandidate(
860
1137
  term,
@@ -868,18 +1145,21 @@ export function scoreCandidate(
868
1145
  prose = [],
869
1146
  guidance = [],
870
1147
  },
871
- {fuzzy = true} = {},
1148
+ {fuzzy = true, joins = true} = {},
872
1149
  ) {
873
1150
  let best = 0;
874
1151
  let reason = '';
1152
+ let alias = false;
875
1153
  /**
876
1154
  * @param {number} score
877
1155
  * @param {string} why
1156
+ * @param {boolean} [byAlias] - the hit reads the query's words joined
878
1157
  */
879
- const consider = (score, why) => {
1158
+ const consider = (score, why, byAlias = false) => {
880
1159
  if (score > best) {
881
1160
  best = score;
882
1161
  reason = why;
1162
+ alias = byAlias;
883
1163
  }
884
1164
  };
885
1165
 
@@ -903,6 +1183,16 @@ export function scoreCandidate(
903
1183
  nameLower === term.replace(/\s+/g, '');
904
1184
  if (nameLower === term || leafLower === term || spelled) {
905
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);
906
1196
  } else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
907
1197
  // One point under the exact spelling, so the doc named `tokens` still
908
1198
  // outranks the Token component for `tokens`.
@@ -926,12 +1216,27 @@ export function scoreCandidate(
926
1216
  }
927
1217
 
928
1218
  // ── Keyword signals ─────────────────────────────────────────────
1219
+ const termJoined = joined(term);
929
1220
  for (const kw of keywords) {
930
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.
931
1227
  if (kwLower === term) {
932
1228
  consider(90, `keyword "${kw}"`);
933
1229
  continue;
934
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
+ }
935
1240
  if (sameWord(term, kwLower)) {
936
1241
  consider(88, `keyword "${kw}"`);
937
1242
  continue;
@@ -963,9 +1268,12 @@ export function scoreCandidate(
963
1268
  // Match the term's stem as a whole word, tolerating plural/gerund suffixes
964
1269
  // so "chart" matches "charts" and "filter" matches "filtering".
965
1270
  if (term.length >= 3) {
966
- const root = stem(term);
967
- const escaped = root.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
968
- 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`);
969
1277
  if (description && re.test(description.toLowerCase())) {
970
1278
  consider(50, `description mentions "${term}"`);
971
1279
  } else {
@@ -991,7 +1299,7 @@ export function scoreCandidate(
991
1299
  }
992
1300
  }
993
1301
 
994
- return best > 0 ? {score: best, reason} : null;
1302
+ return best > 0 ? {score: best, reason, ...(alias ? {alias} : {})} : null;
995
1303
  }
996
1304
 
997
1305
  /**
@@ -1110,20 +1418,57 @@ async function gatherCoreComponents(coreDir) {
1110
1418
  * usage/description from each component's .doc.mjs, same as core. Without
1111
1419
  * this, an integration component is invisible to `search`/`build` even
1112
1420
  * though `component --list`/`component <Name>` already resolve it — the two
1113
- * 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.
1114
1423
  * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
1115
- * @returns {Promise<Candidate[]>}
1424
+ * @returns {Promise<{candidates: Candidate[], fileNamed: Map<string, Set<string>>, documented: Map<string, Set<string>>}>}
1116
1425
  */
1117
1426
  async function gatherIntegrationComponents(loadedIntegrations) {
1118
1427
  /** @type {Candidate[]} */
1119
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));
1120
1439
  for (const integration of loadedIntegrations) {
1121
- 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
+ });
1122
1451
  for (const rec of components) {
1123
- 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
+ }
1124
1466
  candidates.push({
1125
1467
  domain: 'component',
1126
1468
  name: rec.name,
1469
+ aliases: !member && fileName !== rec.name ? [fileName] : [],
1470
+ _hold: integrationRecordHold(rec),
1471
+ _docPath: rec.docPath,
1127
1472
  keywords: doc && Array.isArray(doc.keywords) ? doc.keywords : [],
1128
1473
  description: doc ? doc.usage?.description || doc.description || '' : '',
1129
1474
  guidance: guidanceFrom(doc),
@@ -1143,12 +1488,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1143
1488
  packageName: rec.package,
1144
1489
  },
1145
1490
  rec.name,
1146
- doc?.import,
1491
+ loaded?.import,
1147
1492
  ),
1148
1493
  });
1149
1494
  }
1150
1495
  }
1151
- return candidates;
1496
+ return {candidates, fileNamed, documented};
1152
1497
  }
1153
1498
 
1154
1499
  /**
@@ -1160,11 +1505,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1160
1505
  */
1161
1506
  async function gatherComponents(coreDir, cwd) {
1162
1507
  const loadedIntegrations = await loadIntegrationsSafely(cwd);
1163
- const [core, integrations, replacements] = await Promise.all([
1508
+ const [core, gathered, replacements] = await Promise.all([
1164
1509
  gatherCoreComponents(coreDir),
1165
1510
  gatherIntegrationComponents(loadedIntegrations),
1166
1511
  loadComponentReplacements(coreDir, loadedIntegrations),
1167
1512
  ]);
1513
+ const {candidates: integrations, fileNamed, documented} = gathered;
1168
1514
  // An active replacement answers to the Core name it replaces, so a search
1169
1515
  // for that name finds the replacement and not the Core original
1170
1516
  // (spec:AST-035 FR11).
@@ -1175,9 +1521,43 @@ async function gatherComponents(coreDir, cwd) {
1175
1521
  active.target,
1176
1522
  ]),
1177
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
+ });
1178
1555
  return [
1179
1556
  ...core.filter(candidate => !replacements.forTarget(candidate.name)),
1180
- ...integrations.map(candidate => {
1557
+ ...[
1558
+ ...ruled.filter(candidate => !candidate._command),
1559
+ ...ruled.filter(candidate => candidate._command),
1560
+ ].map(candidate => {
1181
1561
  const target = targetOf.get(`${candidate._package}\0${candidate.name}`);
1182
1562
  if (target != null) {
1183
1563
  return {...candidate, aliases: [...(candidate.aliases ?? []), target]};
@@ -1244,10 +1624,13 @@ export async function componentKeywords(coreDir, cwd) {
1244
1624
  const integrations = loadedIntegrations.map(async integration => {
1245
1625
  const {components} = await discoverValidIntegrationComponents(integration);
1246
1626
  return Promise.all(
1247
- components.map(async rec => ({
1248
- name: rec.name,
1249
- keywords: keywordsOf(await loadModuleDoc(rec.docPath)),
1250
- })),
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
+ }),
1251
1634
  );
1252
1635
  });
1253
1636
  return [
@@ -1421,6 +1804,10 @@ async function gatherDocs(cwd) {
1421
1804
  ...defined,
1422
1805
  ...codeTerms({content}),
1423
1806
  ],
1807
+ _declared: [
1808
+ ...(Array.isArray(selfDoc?.keywords) ? selfDoc.keywords : []),
1809
+ ...(Array.isArray(node.keywords) ? node.keywords : []),
1810
+ ],
1424
1811
  description: node.summary || '',
1425
1812
  prose: sectionProse({title: node.title, content}),
1426
1813
  titles: [node.title],
@@ -1557,6 +1944,7 @@ function topicCandidates(
1557
1944
  ...(doc?.title || title ? [doc?.title || title] : []),
1558
1945
  ...(Array.isArray(doc?.keywords) ? doc.keywords : []),
1559
1946
  ],
1947
+ _declared: Array.isArray(doc?.keywords) ? doc.keywords : [],
1560
1948
  description: doc?.description || summary,
1561
1949
  prose: split
1562
1950
  ? sections.map(section => section.title).filter(Boolean)
@@ -1816,8 +2204,6 @@ async function searchOnce(query, options) {
1816
2204
  }
1817
2205
 
1818
2206
  const term = String(query).trim().toLowerCase();
1819
- const tokens = tokenizeQuery(term);
1820
-
1821
2207
  // `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
1822
2208
  // list` reads themes without it (bundled themes need no project), so a
1823
2209
  // search of either must too. Every other domain reads core: asked for by
@@ -1849,14 +2235,97 @@ async function searchOnce(query, options) {
1849
2235
 
1850
2236
  const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
1851
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
+
1852
2321
  // Score every candidate on its own merits. The consumer groups results by
1853
2322
  // role (page / block / component) and takes the top of each, so there's no
1854
2323
  // cross-role competition to engineer — a target page only needs to be the
1855
2324
  // strongest PAGE, not outrank every component.
1856
- /** @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}[]} */
1857
2326
  const ranked = [];
1858
2327
  for (const candidate of all) {
1859
- const hit = scoreQuery(term, tokens, candidate);
2328
+ const hit = scoreQuery(term, tokens, candidate, words);
1860
2329
  if (hit)
1861
2330
  ranked.push({
1862
2331
  result: toResult(
@@ -1866,9 +2335,43 @@ async function searchOnce(query, options) {
1866
2335
  hit.matched,
1867
2336
  hit.total,
1868
2337
  ),
1869
- 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),
1870
2344
  });
1871
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
+ }
1872
2375
 
1873
2376
  // Docs and everything else are each sorted by score desc, then domain
1874
2377
  // (stable order), then name. The two are merged: at each step the stronger
@@ -1877,11 +2380,11 @@ async function searchOnce(query, options) {
1877
2380
  /** @type {Record<string, number>} */
1878
2381
  const domainOrder = {component: 0, hook: 1, doc: 2, template: 3, theme: 4};
1879
2382
  /**
1880
- * @param {{result: any}} x
1881
- * @param {{result: any}} y
2383
+ * @param {{result: any, key: number}} x
2384
+ * @param {{result: any, key: number}} y
1882
2385
  */
1883
- const byScore = ({result: a}, {result: b}) =>
1884
- b.score - a.score ||
2386
+ const byScore = ({result: a, key: ka}, {result: b, key: kb}) =>
2387
+ kb - ka ||
1885
2388
  (domainOrder[a.domain] ?? 9) - (domainOrder[b.domain] ?? 9) ||
1886
2389
  a.name.localeCompare(b.name);
1887
2390
  const others = ranked.filter(r => r.result.domain !== 'doc').sort(byScore);