@astryxdesign/cli 0.7.2-canary.ab79547 → 0.7.2-canary.b40ba52

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 (255) hide show
  1. package/README.md +20 -19
  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/discover/_adapter.d.mts +119 -12
  8. package/api/discover/_adapter.mjs +449 -10
  9. package/api/discover/_adapter.test.mjs +599 -17
  10. package/api/discover/_catalog-view.d.mts +16 -5
  11. package/api/discover/_catalog-view.mjs +32 -8
  12. package/api/discover/discover.d.mts +11 -0
  13. package/api/discover/discover.doc.mjs +7 -6
  14. package/api/discover/discover.mjs +107 -19
  15. package/api/discover/discover.type.d.mts +18 -7
  16. package/api/discover/discover.type.mjs +15 -7
  17. package/api/discover/list/list.d.mts +4 -3
  18. package/api/discover/list/list.mjs +17 -10
  19. package/api/docs/_adapter.d.mts +11 -0
  20. package/api/docs/_adapter.mjs +244 -1
  21. package/api/docs/integrationDocs.test.mjs +124 -0
  22. package/api/doctor/doctor.mjs +27 -3
  23. package/api/doctor/doctor.test.mjs +43 -0
  24. package/api/doctor/theme-checks.mjs +1 -1
  25. package/api/doctor/theme-checks.test.mjs +136 -0
  26. package/api/gap-report/gap-report.d.mts +3 -0
  27. package/api/gap-report/gap-report.doc.mjs +11 -3
  28. package/api/gap-report/gap-report.mjs +219 -52
  29. package/api/gap-report/gap-report.test.mjs +233 -0
  30. package/api/gap-report/gap-report.type.d.mts +41 -0
  31. package/api/gap-report/gap-report.type.mjs +18 -0
  32. package/api/index.d.mts +2 -0
  33. package/api/index.mjs +2 -0
  34. package/api/init/run/run.mjs +2 -2
  35. package/api/integration/_adapter.d.mts +12 -0
  36. package/api/integration/_adapter.mjs +54 -0
  37. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  38. package/api/integration/add-contribution.mjs +8 -4
  39. package/api/integration/add-contribution.test.mjs +4 -2
  40. package/api/integration/authoring-checks.mjs +11 -2
  41. package/api/integration/authoring-checks.test.mjs +39 -0
  42. package/api/integration/authoring-checks.type.d.mts +9 -0
  43. package/api/integration/authoring-checks.type.mjs +14 -1
  44. package/api/integration/check/check.d.mts +96 -0
  45. package/api/integration/check/check.mjs +357 -0
  46. package/api/integration/check/check.test.mjs +489 -0
  47. package/api/integration/integration-check.type.d.mts +118 -0
  48. package/api/integration/integration-check.type.mjs +84 -0
  49. package/api/integration/integrationCheck.doc.d.mts +10 -0
  50. package/api/integration/integrationCheck.doc.mjs +73 -0
  51. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  52. package/api/integration/pack-check.mjs +343 -104
  53. package/api/integration/pack-check.test.mjs +700 -0
  54. package/api/integration/validate-integration.mjs +8 -0
  55. package/api/integration/validate-integration.test.mjs +11 -0
  56. package/api/integration/validate-integration.type.d.mts +8 -0
  57. package/api/integration/validate-integration.type.mjs +12 -1
  58. package/api/integration/validateIntegration.doc.mjs +19 -3
  59. package/api/search/search.d.mts +81 -12
  60. package/api/search/search.domain-priority.test.mjs +108 -18
  61. package/api/search/search.integration-check.test.mjs +24 -0
  62. package/api/search/search.mjs +601 -50
  63. package/api/search/search.test.mjs +139 -0
  64. package/api/swizzle/copy/copy.mjs +28 -14
  65. package/api/theme/build/build.family.test.mjs +54 -6
  66. package/api/theme/build/build.mjs +114 -17
  67. package/api/theme/themeBuild.doc.mjs +4 -4
  68. package/api/upgrade/_adapter.d.mts +40 -2
  69. package/api/upgrade/_adapter.mjs +117 -4
  70. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  71. package/api/upgrade/run/run.mjs +30 -1
  72. package/api/upgrade/status/status.d.mts +21 -5
  73. package/api/upgrade/status/status.mjs +45 -8
  74. package/api/upgrade/upgrade.doc.mjs +5 -3
  75. package/api/upgrade/upgrade.type.d.mts +23 -0
  76. package/api/upgrade/upgrade.type.mjs +16 -1
  77. package/assets/codemods/runner.mjs +7 -1
  78. package/assets/discover/official-packages.json +367 -0
  79. package/assets/docs/README.md +10 -0
  80. package/assets/docs/author-a-theme.doc.mjs +1 -1
  81. package/assets/docs/getting-started.doc.mjs +3 -3
  82. package/assets/docs/styling-overview.doc.mjs +1 -1
  83. package/assets/docs/theme.doc.dense.mjs +1 -1
  84. package/assets/docs/theme.doc.mjs +1 -1
  85. package/assets/docs/theme.doc.zh.mjs +1 -1
  86. package/assets/docs/tree/add-a-component.doc.mjs +11 -1
  87. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  88. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  89. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  90. package/assets/docs/tree/block-template.doc.mjs +8 -20
  91. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  92. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  93. package/assets/docs/tree/check-your-docs.doc.mjs +51 -5
  94. package/assets/docs/tree/checks.doc.mjs +24 -16
  95. package/assets/docs/tree/codemods.doc.mjs +4 -4
  96. package/assets/docs/tree/component-family.doc.mjs +8 -6
  97. package/assets/docs/tree/component-imports.doc.mjs +10 -2
  98. package/assets/docs/tree/components.doc.mjs +1 -1
  99. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +25 -16
  100. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  101. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  102. package/assets/docs/tree/docs.doc.mjs +3 -3
  103. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  104. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  105. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  106. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  107. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  108. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  109. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  110. package/assets/docs/tree/integrations.doc.mjs +8 -0
  111. package/assets/docs/tree/links.doc.mjs +6 -5
  112. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  113. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  114. package/assets/docs/tree/migration.doc.mjs +0 -1
  115. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  116. package/assets/docs/tree/page-template.doc.mjs +4 -8
  117. package/assets/docs/tree/publishing.doc.mjs +1 -1
  118. package/assets/docs/tree/quick-start.doc.mjs +37 -21
  119. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  120. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  121. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  122. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  123. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  124. package/assets/docs/tree/single-component.doc.mjs +15 -6
  125. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  126. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  127. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  128. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  129. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  130. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  131. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  132. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  133. package/assets/docs/tree/templates.doc.mjs +1 -1
  134. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  135. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  136. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  137. package/assets/docs/tree/troubleshooting.doc.mjs +13 -5
  138. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  139. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  140. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  141. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  142. package/assets/docs/tree/versioning.doc.mjs +7 -6
  143. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  144. package/assets/docs/use-a-theme.doc.mjs +2 -2
  145. package/assets/theme.template.ts +1 -1
  146. package/authoring/codemod/codemod.doc.mjs +7 -3
  147. package/authoring/config/config.doc.mjs +9 -6
  148. package/authoring/config/type.ts +4 -2
  149. package/authoring/discover/discover.doc.mjs +1 -1
  150. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  151. package/authoring/doctypes/command/command.doc.mjs +14 -12
  152. package/authoring/doctypes/component/component.doc.mjs +29 -26
  153. package/authoring/doctypes/component/type.ts +13 -8
  154. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  155. package/authoring/doctypes/function/function.doc.mjs +9 -8
  156. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  157. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  158. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  159. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  160. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  161. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  162. package/authoring/doctypes/template/parse.d.mts +6 -2
  163. package/authoring/doctypes/template/parse.mjs +3 -1
  164. package/authoring/doctypes/template/template.doc.mjs +3 -3
  165. package/authoring/doctypes/template/type.ts +22 -0
  166. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  167. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  168. package/authoring/identity/identity.doc.mjs +3 -3
  169. package/authoring/index.d.ts +1 -0
  170. package/authoring/integration/integration.doc.mjs +12 -4
  171. package/authoring/integration/parse.test.mjs +10 -0
  172. package/authoring/integration/schema.d.mts +2 -0
  173. package/authoring/integration/schema.mjs +1 -0
  174. package/authoring/integration/type.ts +4 -0
  175. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  176. package/clients/cli/commands/build-theme.mjs +1 -1
  177. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  178. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  179. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  180. package/clients/cli/commands/discover.doc.mjs +1 -1
  181. package/clients/cli/commands/discover.mjs +144 -93
  182. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  183. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  184. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  185. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  186. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  187. package/clients/cli/commands/doctor.mjs +190 -0
  188. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  189. package/clients/cli/commands/gap-report.mjs +24 -2
  190. package/clients/cli/commands/gap-report.test.mjs +79 -0
  191. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  192. package/clients/cli/commands/integration-check.test.mjs +284 -0
  193. package/clients/cli/commands/integration.doc.mjs +6 -2
  194. package/clients/cli/commands/integration.mjs +106 -1
  195. package/clients/cli/commands/json-contract.test.mjs +5 -1
  196. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  197. package/clients/cli/commands/swizzle.mjs +5 -3
  198. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  199. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  200. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  201. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  202. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  203. package/clients/cli/index.mjs +30 -5
  204. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  205. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  206. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  207. package/foundation/agent-docs/agent-docs.mjs +8 -6
  208. package/foundation/config/project.mjs +82 -0
  209. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  210. package/foundation/discovery/component-discovery.d.mts +178 -10
  211. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  212. package/foundation/discovery/component-discovery.mjs +659 -62
  213. package/foundation/discovery/component-replacement.mjs +18 -0
  214. package/foundation/discovery/component-replacement.test.mjs +40 -0
  215. package/foundation/discovery/doc-types.d.mts +157 -0
  216. package/foundation/discovery/doc-types.mjs +1224 -0
  217. package/foundation/discovery/doc-types.test.mjs +700 -0
  218. package/foundation/discovery/docs-discovery.d.mts +81 -0
  219. package/foundation/discovery/docs-discovery.mjs +57 -0
  220. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  221. package/foundation/discovery/integration-doc-files.mjs +231 -0
  222. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  223. package/foundation/discovery/module-exports.d.mts +27 -0
  224. package/foundation/discovery/module-exports.mjs +356 -31
  225. package/foundation/discovery/module-exports.test.mjs +172 -0
  226. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  227. package/foundation/discovery/package-tsconfig.mjs +228 -0
  228. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  229. package/foundation/discovery/project-typescript.d.mts +32 -0
  230. package/foundation/discovery/project-typescript.mjs +89 -0
  231. package/foundation/discovery/prop-drift.d.mts +278 -0
  232. package/foundation/discovery/prop-drift.mjs +2263 -0
  233. package/foundation/discovery/prop-drift.test.mjs +2272 -0
  234. package/foundation/discovery/type-match.d.mts +53 -0
  235. package/foundation/discovery/type-match.mjs +660 -0
  236. package/foundation/discovery/type-match.test.mjs +169 -0
  237. package/foundation/discovery/type-text.d.mts +68 -0
  238. package/foundation/discovery/type-text.mjs +658 -0
  239. package/foundation/discovery/type-text.test.mjs +196 -0
  240. package/foundation/discovery/unresolved-references.d.mts +62 -0
  241. package/foundation/discovery/unresolved-references.mjs +790 -0
  242. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  243. package/foundation/doc-compiler/doc-loads.test.mjs +10 -0
  244. package/foundation/doc-compiler/links.d.mts +9 -5
  245. package/foundation/doc-compiler/links.mjs +4 -2
  246. package/foundation/env/package-manager.d.mts +32 -0
  247. package/foundation/env/package-manager.mjs +47 -0
  248. package/foundation/env/package-manager.test.mjs +194 -7
  249. package/foundation/fs/module-loader.d.mts +2 -1
  250. package/foundation/fs/module-loader.mjs +60 -4
  251. package/foundation/fs/module-loader.test.mjs +194 -0
  252. package/foundation/integrations/contribution-inventory.mjs +6 -1
  253. package/foundation/response/response-types.doc.mjs +13 -7
  254. package/package.json +9 -9
  255. 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,201 @@ 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();
290
352
  }
291
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?: 'partial' | 'keyword', aliasWords?: number} | 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?: 'partial' | 'keyword', aliasWords?: number} | null} */
410
+ let best = null;
411
+ for (const {run, word} of queryRuns(words)) {
412
+ let score = 0;
413
+ let reason = '';
414
+ /** @type {'partial' | 'keyword' | null} */
415
+ let kind = null;
416
+ for (const {name, nameJoined, nameWords} of names) {
417
+ if (
418
+ nameJoined === word ||
419
+ pluralOf(word, nameJoined) ||
420
+ (candidate.domain === 'hook' && nameJoined === `use${word}`)
421
+ ) {
422
+ if (score < 100)
423
+ [score, reason, kind] = [100, `name ${name} spelled`, null];
424
+ } else if (!partial) {
425
+ continue;
426
+ } else if (
427
+ nameJoined.startsWith(word) &&
428
+ word.length / nameJoined.length >= 0.75
429
+ ) {
430
+ // Most of the name, cut short: `dropdown menu radio` is
431
+ // DropdownMenuRadioItem.
432
+ if (score < 95)
433
+ [score, reason, kind] = [95, `name ${name} spelled`, 'partial'];
434
+ } else if (
435
+ word.length / nameJoined.length >= 0.5 &&
436
+ run.every(
437
+ (w, j) => nameWords[j + (nameWords[0] === 'use' ? 1 : 0)] === w,
438
+ )
439
+ ) {
440
+ // The name's leading words: `top nav mega` is TopNavMegaMenu.
441
+ if (score < 92)
442
+ [score, reason, kind] = [
443
+ 92,
444
+ `name ${name} starts "${run.join(' ')}"`,
445
+ 'partial',
446
+ ];
447
+ } else if (
448
+ word.length / nameJoined.length >= 0.5 &&
449
+ nameWords.some((_, k) => run.every((w, j) => nameWords[k + j] === w))
450
+ ) {
451
+ if (score < 70)
452
+ [score, reason, kind] = [
453
+ 70,
454
+ `name ${name} holds "${run.join(' ')}"`,
455
+ 'partial',
456
+ ];
457
+ }
458
+ }
459
+ if (score < 90 && keywords.includes(word)) {
460
+ [score, reason, kind] = [
461
+ 90,
462
+ `keyword "${run.join(' ')}" spelled`,
463
+ 'keyword',
464
+ ];
465
+ }
466
+ if (score > (best?.score ?? 0)) {
467
+ // Each word of the run, and each identifier typed as several of its
468
+ // words joined (`dropdownMenu` in `dropdownMenu checkbox`).
469
+ const covered = new Set();
470
+ for (let a = 0; a < run.length; a++) {
471
+ for (let b = a + 1; b <= run.length; b++) {
472
+ covered.add(run.slice(a, b).join(''));
473
+ }
474
+ }
475
+ best = {
476
+ score,
477
+ reason,
478
+ covered,
479
+ ...(kind ? {alias: kind, aliasWords: run.length} : {}),
480
+ };
481
+ }
482
+ }
483
+ return best;
484
+ }
485
+
486
+ /**
487
+ * The longest run of adjacent query words read as one name. Core's longest
488
+ * names run to six words; a longer run is a sentence, not a name, and reading
489
+ * every run of a long build idea costs time on every candidate.
490
+ */
491
+ const MAX_RUN_WORDS = 6;
492
+
493
+ /**
494
+ * Each run of two to {@link MAX_RUN_WORDS} adjacent query words, longest
495
+ * first, with the run joined into one word. Computed once per query.
496
+ * @type {WeakMap<string[], {run: string[], word: string}[]>}
497
+ */
498
+ const runsOf = new WeakMap();
499
+
500
+ /**
501
+ * @param {string[]} words
502
+ * @returns {{run: string[], word: string}[]}
503
+ */
504
+ function queryRuns(words) {
505
+ let runs = runsOf.get(words);
506
+ if (runs) return runs;
507
+ runs = [];
508
+ for (let len = Math.min(words.length, MAX_RUN_WORDS); len >= 2; len--) {
509
+ for (let i = 0; i + len <= words.length; i++) {
510
+ const run = words.slice(i, i + len);
511
+ runs.push({run, word: run.join('')});
512
+ }
513
+ }
514
+ runsOf.set(words, runs);
515
+ return runs;
516
+ }
517
+
518
+ /**
519
+ * Each candidate's compound hit from its last scoreQuery, so domainPriority
520
+ * reads it without walking the query's runs again.
521
+ * @type {WeakMap<object, ReturnType<typeof compoundHit>>}
522
+ */
523
+ const compoundOf = new WeakMap();
524
+
292
525
  /**
293
526
  * The fewest letters both words need before an edit distance counts as a
294
527
  * typo, by distance. Below them, one edit usually makes a different word.
@@ -501,19 +734,20 @@ const STRONG_TOKEN_SCORE = 70;
501
734
  * typography/font-setup, `side panel` is "Side panels");
502
735
  * - 1: a word of the query is the topic's name (`illustration` in a longer
503
736
  * question is the illustrations guide);
737
+ * - 1: a query of two or more words is one of the topic's own declared
738
+ * keywords, whatever the plural (`code review` on a guide that declares it);
504
739
  * - 1: the query holds one of the doc's titles whole (`resizable side panels`
505
740
  * names "Side panels"; `light dark mode button` names "Light/Dark Mode");
506
741
  * - 1: the doc matches every word of the query and one of them is a word of
507
742
  * its title (`switch to a dark theme` and "Use a theme").
508
743
  * A section answers to its topic's name.
509
744
  *
510
- * A doc that matched only by keyword, by a heading holding the query, or by
745
+ * A doc that matched only by a heading holding the query, by one word, or by
511
746
  * 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
747
+ * small topics, each with its own headings, so a common phrase such as
748
+ * `font size` hits a heading exactly (170) while the component the reader is
749
+ * after matches one word by keyword (`Text`, 98). Ranked on text alone, every
750
+ * split adds another doc above the component. Broad reference pages match every word of many queries
517
751
  * in their text the same way. The score stays the text-match strength the
518
752
  * result reports, so callers that gate on it (`build`) see the same numbers.
519
753
  *
@@ -524,7 +758,13 @@ const STRONG_TOKEN_SCORE = 70;
524
758
  * candidate's scoreQuery result.
525
759
  * @returns {0 | 1 | 2}
526
760
  */
527
- export function domainPriority(term, tokens, candidate, hit) {
761
+ export function domainPriority(
762
+ term,
763
+ tokens,
764
+ candidate,
765
+ hit,
766
+ queryWords = phraseWords(term),
767
+ ) {
528
768
  const words = [term, ...tokens];
529
769
  if (candidate.domain === 'doc') {
530
770
  const topic = String(candidate._topic ?? candidate.name).toLowerCase();
@@ -539,6 +779,20 @@ export function domainPriority(term, tokens, candidate, hit) {
539
779
  if (named.some(n => samePhrase(term, n))) {
540
780
  return 2;
541
781
  }
782
+ // A query of two or more words that is one of the doc's own declared
783
+ // keywords, read as words whatever the plural, is the author naming the
784
+ // doc for that phrase: `code review` on a guide that declares it. Only
785
+ // what the author declared counts: the code terms and table cells a
786
+ // doc's other keywords add (`missing_field`) name what it mentions, not
787
+ // what it is for. One word is left out too, and a section declares
788
+ // nothing.
789
+ if (
790
+ phraseWords(term).length >= 2 &&
791
+ candidate._section == null &&
792
+ (candidate._declared ?? []).some(k => samePhrase(term, String(k)))
793
+ ) {
794
+ return 1;
795
+ }
542
796
  if (
543
797
  words.some(
544
798
  w =>
@@ -569,6 +823,12 @@ export function domainPriority(term, tokens, candidate, hit) {
569
823
  return 0;
570
824
  }
571
825
  if (hit.score >= FULL_COVERAGE_SCORE) return 1;
826
+ const compound = compoundOf.has(candidate)
827
+ ? compoundOf.get(candidate)
828
+ : compoundHit(queryWords, candidate);
829
+ if ((compound?.score ?? 0) >= STRONG_TOKEN_SCORE) {
830
+ return 1;
831
+ }
572
832
  const fuzzy = tokens.length <= 1;
573
833
  return words.some(
574
834
  w =>
@@ -684,14 +944,24 @@ export function titleInQuery(term, titles) {
684
944
  * @param {string} term - Lowercased full query.
685
945
  * @param {string[]} tokens - Content tokens from tokenizeQuery(term).
686
946
  * @param {Candidate} candidate
687
- * @returns {{score: number, reason: string, matched: number, total: number} | null}
947
+ * @param {string[]} [words] - The query's words for compound names (see
948
+ * compoundHit); empty when the query names an entry outright.
949
+ * @param {{plain?: boolean}} [opts] - `plain`: score without matches on part
950
+ * of a name or a joined keyword.
951
+ * @returns {{score: number, reason: string, matched: number, total: number, alias?: 'partial' | 'keyword', aliasWords?: number} | null}
688
952
  * `matched`/`total` are the query concepts this candidate answered, out of
689
953
  * the concepts the query had. Callers that must distinguish "matched one word
690
954
  * of three" from "matched all three" — `build`, which gates its pages group
691
955
  * on coverage — cannot recover that from the score, because a single strong
692
956
  * hit and a broad weak one land on the same number.
693
957
  */
694
- export function scoreQuery(term, tokens, candidate) {
958
+ export function scoreQuery(
959
+ term,
960
+ tokens,
961
+ candidate,
962
+ words = phraseWords(term),
963
+ {plain = false} = {},
964
+ ) {
695
965
  const total = Math.max(tokens.length, 1);
696
966
  // A whole-phrase hit answered the whole query by definition.
697
967
  const asFull = (/** @type {{score: number, reason: string}} */ hit) => ({
@@ -700,14 +970,24 @@ export function scoreQuery(term, tokens, candidate) {
700
970
  total,
701
971
  });
702
972
  // 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});
973
+ // is usually a different word, not a typo. One typed identifier is one
974
+ // word, whatever words it spells.
975
+ const fuzzy = tokens.length <= 1 || !/\s/.test(term);
976
+ const full = scoreCandidate(term, candidate, {
977
+ fuzzy,
978
+ joins: !plain && words.length > 0,
979
+ });
706
980
  // A query of several words keeps its phrase tiers below even when stopwords
707
981
  // leave one content word: "make an integration" is still the phrase an
708
982
  // author declares as a keyword, and "build an integration" still names a
709
983
  // title outright, though each tokenizes to `integration` alone.
710
- const phrase = phraseWords(term).length >= 2;
984
+ const phrase = phraseWords(term).length >= 2 || words.length >= 2;
985
+ let compound = compoundHit(words, candidate);
986
+ if (plain) {
987
+ if (compound?.alias) compound = null;
988
+ } else {
989
+ compoundOf.set(candidate, compound);
990
+ }
711
991
 
712
992
  /** 0–1 content tokens: whole-phrase fuzzy matching (typo tolerance for
713
993
  * single words), but if stopwords left exactly one DIFFERENT token (e.g.
@@ -732,7 +1012,11 @@ export function scoreQuery(term, tokens, candidate) {
732
1012
  // of Table-related templates each match "table" and "contents" separately
733
1013
  // and accumulate a higher raw score (#5239).
734
1014
  if (full && full.score >= 90) {
735
- return asFull({score: full.score + 100, reason: full.reason});
1015
+ return asFull({
1016
+ score: full.score + 100,
1017
+ reason: full.reason,
1018
+ ...(full.alias ? {alias: full.alias, aliasWords: words.length} : {}),
1019
+ });
736
1020
  }
737
1021
 
738
1022
  // The whole query standing as a phrase in a doc's title or one of its
@@ -758,8 +1042,25 @@ export function scoreQuery(term, tokens, candidate) {
758
1042
  let tokenSum = 0;
759
1043
  /** @type {string[]} */
760
1044
  const hitTerms = [];
1045
+ // Adjacent words that join into a name or keyword answer each word they
1046
+ // join, as strongly as the joined word matches (see compoundHit).
1047
+ // Whether a counted word matched only through part of a name or a keyword
1048
+ // read joined, not through the entry's own name or a word of it.
1049
+ /** @type {'partial' | 'keyword' | false} */
1050
+ let alias = false;
1051
+ let aliasWords = 0;
761
1052
  for (const tok of tokens) {
762
- const h = bestForToken(tok, candidate, {fuzzy});
1053
+ let h = bestForToken(tok, candidate, {fuzzy});
1054
+ if (
1055
+ compound?.covered.has(joined(tok)) &&
1056
+ compound.score > (h?.score ?? 0)
1057
+ ) {
1058
+ h = compound;
1059
+ if (compound.alias && compound.score >= MIN_TOKEN_SCORE) {
1060
+ alias = alias === 'partial' ? alias : compound.alias;
1061
+ aliasWords = compound.aliasWords ?? 0;
1062
+ }
1063
+ }
763
1064
  if (h && h.score >= MIN_TOKEN_SCORE) {
764
1065
  if (h.score > strongest) strongest = h.score;
765
1066
  matched++;
@@ -809,6 +1110,7 @@ export function scoreQuery(term, tokens, candidate) {
809
1110
  reason,
810
1111
  matched,
811
1112
  total,
1113
+ ...(alias ? {alias, aliasWords} : {}),
812
1114
  };
813
1115
  }
814
1116
 
@@ -834,7 +1136,13 @@ export function scoreQuery(term, tokens, candidate) {
834
1136
  strongest + Math.min(matched - 1, 3) * 12 + coverage * 15,
835
1137
  );
836
1138
  if (full && full.score >= tokenScore) return asFull(full);
837
- return {score: tokenScore, reason, matched, total};
1139
+ return {
1140
+ score: tokenScore,
1141
+ reason,
1142
+ matched,
1143
+ total,
1144
+ ...(alias ? {alias, aliasWords} : {}),
1145
+ };
838
1146
  }
839
1147
 
840
1148
  /**
@@ -853,8 +1161,9 @@ export function scoreQuery(term, tokens, candidate) {
853
1161
  * @param {string} [candidate.description]
854
1162
  * @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
855
1163
  * @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}
1164
+ * @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.
1165
+ * @returns {{score: number, reason: string, alias?: 'partial' | 'keyword'} | null}
1166
+ * `alias` marks a hit that read the query's words joined.
858
1167
  */
859
1168
  export function scoreCandidate(
860
1169
  term,
@@ -868,18 +1177,23 @@ export function scoreCandidate(
868
1177
  prose = [],
869
1178
  guidance = [],
870
1179
  },
871
- {fuzzy = true} = {},
1180
+ {fuzzy = true, joins = true} = {},
872
1181
  ) {
873
1182
  let best = 0;
874
1183
  let reason = '';
1184
+ /** @type {'partial' | 'keyword' | false} */
1185
+ let alias = false;
875
1186
  /**
876
1187
  * @param {number} score
877
1188
  * @param {string} why
1189
+ * @param {'partial' | 'keyword' | false} [byAlias] - the hit reads the
1190
+ * query's words joined, into part of a name or into a keyword
878
1191
  */
879
- const consider = (score, why) => {
1192
+ const consider = (score, why, byAlias = false) => {
880
1193
  if (score > best) {
881
1194
  best = score;
882
1195
  reason = why;
1196
+ alias = byAlias;
883
1197
  }
884
1198
  };
885
1199
 
@@ -903,6 +1217,16 @@ export function scoreCandidate(
903
1217
  nameLower === term.replace(/\s+/g, '');
904
1218
  if (nameLower === term || leafLower === term || spelled) {
905
1219
  consider(100, 'exact name');
1220
+ } else if (
1221
+ joins &&
1222
+ (domain === 'component' || domain === 'hook') &&
1223
+ /\s/.test(term) &&
1224
+ nameLower.startsWith(term.replace(/\s+/g, '')) &&
1225
+ term.replace(/\s+/g, '').length / nameLower.length >= 0.75
1226
+ ) {
1227
+ // Most of the name typed as words, cut short: `complex select` is
1228
+ // ComplexSelector, ahead of a one-word keyword elsewhere.
1229
+ consider(95, `name "${candidateName}" spelled`, 'partial');
906
1230
  } else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
907
1231
  // One point under the exact spelling, so the doc named `tokens` still
908
1232
  // outranks the Token component for `tokens`.
@@ -926,12 +1250,27 @@ export function scoreCandidate(
926
1250
  }
927
1251
 
928
1252
  // ── Keyword signals ─────────────────────────────────────────────
1253
+ const termJoined = joined(term);
929
1254
  for (const kw of keywords) {
930
1255
  const kwLower = String(kw).toLowerCase();
1256
+ // A one-word keyword typed as separate words is the keyword: `number
1257
+ // field` is `numberfield`. Only a
1258
+ // lowercase keyword, one an author declares for a reader to type: a
1259
+ // capitalized one names another entry (a block's `componentsUsed`). A
1260
+ // doc's keywords include code terms, matched as written.
931
1261
  if (kwLower === term) {
932
1262
  consider(90, `keyword "${kw}"`);
933
1263
  continue;
934
1264
  }
1265
+ if (
1266
+ joins &&
1267
+ domain !== 'doc' &&
1268
+ /\s/.test(term) &&
1269
+ String(kw) === termJoined
1270
+ ) {
1271
+ consider(90, `keyword "${kw}"`, 'keyword');
1272
+ continue;
1273
+ }
935
1274
  if (sameWord(term, kwLower)) {
936
1275
  consider(88, `keyword "${kw}"`);
937
1276
  continue;
@@ -963,9 +1302,12 @@ export function scoreCandidate(
963
1302
  // Match the term's stem as a whole word, tolerating plural/gerund suffixes
964
1303
  // so "chart" matches "charts" and "filter" matches "filtering".
965
1304
  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`);
1305
+ // Any form of the term, with any common suffix: `spacing` finds
1306
+ // "space" and "spaces", `tables` finds "table".
1307
+ const roots = [...new Set([stem(term), ...wordForms(term)])]
1308
+ .filter(f => f.length >= 3)
1309
+ .map(f => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
1310
+ const re = new RegExp(`\\b(?:${roots.join('|')})(s|es|ing|ed|ies)?\\b`);
969
1311
  if (description && re.test(description.toLowerCase())) {
970
1312
  consider(50, `description mentions "${term}"`);
971
1313
  } else {
@@ -991,7 +1333,7 @@ export function scoreCandidate(
991
1333
  }
992
1334
  }
993
1335
 
994
- return best > 0 ? {score: best, reason} : null;
1336
+ return best > 0 ? {score: best, reason, ...(alias ? {alias} : {})} : null;
995
1337
  }
996
1338
 
997
1339
  /**
@@ -1110,20 +1452,57 @@ async function gatherCoreComponents(coreDir) {
1110
1452
  * usage/description from each component's .doc.mjs, same as core. Without
1111
1453
  * this, an integration component is invisible to `search`/`build` even
1112
1454
  * though `component --list`/`component <Name>` already resolve it — the two
1113
- * discovery paths silently disagreed.
1455
+ * discovery paths silently disagreed. Also returns, per name, the docs that
1456
+ * hold it by their file name and the loadable docs that only record it.
1114
1457
  * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
1115
- * @returns {Promise<Candidate[]>}
1458
+ * @returns {Promise<{candidates: Candidate[], fileNamed: Map<string, Set<string>>, documented: Map<string, Set<string>>}>}
1116
1459
  */
1117
1460
  async function gatherIntegrationComponents(loadedIntegrations) {
1118
1461
  /** @type {Candidate[]} */
1119
1462
  const candidates = [];
1463
+ // What the owner rule reads: the docs that hold a name by their file name,
1464
+ // loadable or not and hidden ones too, and the loadable docs that only
1465
+ // record it.
1466
+ /** @type {Map<string, Set<string>>} */
1467
+ const fileNamed = new Map();
1468
+ /** @type {Map<string, Set<string>>} */
1469
+ const documented = new Map();
1470
+ /** @param {Map<string, Set<string>>} map @param {string} name @param {string} docPath */
1471
+ const hold = (map, name, docPath) =>
1472
+ map.set(name, (map.get(name) ?? new Set()).add(docPath));
1120
1473
  for (const integration of loadedIntegrations) {
1121
- const {components} = await discoverValidIntegrationComponents(integration);
1474
+ const {components, discovered} =
1475
+ await discoverValidIntegrationComponents(integration);
1476
+ const renamed = new Set(
1477
+ discovered
1478
+ .filter(rec => integrationRecordHold(rec) === 'doc')
1479
+ .filter(rec => !isIntegrationMember(rec))
1480
+ .map(rec => rec.docPath),
1481
+ );
1482
+ forEachIntegrationDoc(integration.components, (docPath, stem) => {
1483
+ if (!renamed.has(docPath)) hold(fileNamed, stem, docPath);
1484
+ });
1122
1485
  for (const rec of components) {
1123
- const doc = await loadModuleDoc(rec.docPath);
1486
+ const loaded = await loadModuleDoc(rec.docPath);
1487
+ // A family member is indexed from its own entry: the family's keywords
1488
+ // and guidance describe the family.
1489
+ const member = isIntegrationMember(rec);
1490
+ const doc = member ? integrationMemberEntry(loaded, rec) : loaded;
1491
+ // A doc that names another export of its file still answers to the
1492
+ // file's name, as `component <file name>` does.
1493
+ const fileName = docStem(rec.docPath);
1494
+ if (integrationRecordHold(rec) === 'doc') {
1495
+ hold(documented, rec.name, rec.docPath);
1496
+ }
1497
+ if (renamed.has(rec.docPath) && !member) {
1498
+ hold(documented, fileName, rec.docPath);
1499
+ }
1124
1500
  candidates.push({
1125
1501
  domain: 'component',
1126
1502
  name: rec.name,
1503
+ aliases: !member && fileName !== rec.name ? [fileName] : [],
1504
+ _hold: integrationRecordHold(rec),
1505
+ _docPath: rec.docPath,
1127
1506
  keywords: doc && Array.isArray(doc.keywords) ? doc.keywords : [],
1128
1507
  description: doc ? doc.usage?.description || doc.description || '' : '',
1129
1508
  guidance: guidanceFrom(doc),
@@ -1143,12 +1522,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1143
1522
  packageName: rec.package,
1144
1523
  },
1145
1524
  rec.name,
1146
- doc?.import,
1525
+ loaded?.import,
1147
1526
  ),
1148
1527
  });
1149
1528
  }
1150
1529
  }
1151
- return candidates;
1530
+ return {candidates, fileNamed, documented};
1152
1531
  }
1153
1532
 
1154
1533
  /**
@@ -1160,11 +1539,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1160
1539
  */
1161
1540
  async function gatherComponents(coreDir, cwd) {
1162
1541
  const loadedIntegrations = await loadIntegrationsSafely(cwd);
1163
- const [core, integrations, replacements] = await Promise.all([
1542
+ const [core, gathered, replacements] = await Promise.all([
1164
1543
  gatherCoreComponents(coreDir),
1165
1544
  gatherIntegrationComponents(loadedIntegrations),
1166
1545
  loadComponentReplacements(coreDir, loadedIntegrations),
1167
1546
  ]);
1547
+ const {candidates: integrations, fileNamed, documented} = gathered;
1168
1548
  // An active replacement answers to the Core name it replaces, so a search
1169
1549
  // for that name finds the replacement and not the Core original
1170
1550
  // (spec:AST-035 FR11).
@@ -1175,9 +1555,43 @@ async function gatherComponents(coreDir, cwd) {
1175
1555
  active.target,
1176
1556
  ]),
1177
1557
  );
1558
+ // The owner rule, as component detail applies it: a candidate `component
1559
+ // <name>` does not open names its package and follows the owner, and a
1560
+ // file-name alias that opens another owner is dropped.
1561
+ const coreNames = new Set(core.map(candidate => candidate.name));
1562
+ /** @param {string} name @param {Candidate} candidate */
1563
+ const opens = (name, candidate) =>
1564
+ !coreNames.has(name) &&
1565
+ findComponentReadme(coreDir, name) == null &&
1566
+ [...(fileNamed.get(name) ?? [])].every(doc => doc === candidate._docPath) &&
1567
+ [...(documented.get(name) ?? [])].every(doc => doc === candidate._docPath);
1568
+ // A legacy docs package keeps an exact name over an export name a doc records.
1569
+ /** @type {ReturnType<typeof discoverExternalPackages> | undefined} */
1570
+ let externals;
1571
+ /** @param {string} name */
1572
+ const legacyDocuments = name =>
1573
+ (externals ??= discoverExternalPackages(cwd)).some(
1574
+ ext => resolveLegacyExternalDoc(ext, name) != null,
1575
+ );
1576
+ const ruled = integrations.map(candidate => {
1577
+ const aliases = (candidate.aliases ?? []).filter(alias =>
1578
+ opens(alias, candidate),
1579
+ );
1580
+ return candidate._hold === 'doc' &&
1581
+ (!opens(candidate.name, candidate) || legacyDocuments(candidate.name))
1582
+ ? {
1583
+ ...candidate,
1584
+ aliases,
1585
+ _command: `astryx component ${candidate.name} --package ${candidate._package}`,
1586
+ }
1587
+ : {...candidate, aliases};
1588
+ });
1178
1589
  return [
1179
1590
  ...core.filter(candidate => !replacements.forTarget(candidate.name)),
1180
- ...integrations.map(candidate => {
1591
+ ...[
1592
+ ...ruled.filter(candidate => !candidate._command),
1593
+ ...ruled.filter(candidate => candidate._command),
1594
+ ].map(candidate => {
1181
1595
  const target = targetOf.get(`${candidate._package}\0${candidate.name}`);
1182
1596
  if (target != null) {
1183
1597
  return {...candidate, aliases: [...(candidate.aliases ?? []), target]};
@@ -1244,10 +1658,13 @@ export async function componentKeywords(coreDir, cwd) {
1244
1658
  const integrations = loadedIntegrations.map(async integration => {
1245
1659
  const {components} = await discoverValidIntegrationComponents(integration);
1246
1660
  return Promise.all(
1247
- components.map(async rec => ({
1248
- name: rec.name,
1249
- keywords: keywordsOf(await loadModuleDoc(rec.docPath)),
1250
- })),
1661
+ components.map(async rec => {
1662
+ const loaded = await loadModuleDoc(rec.docPath);
1663
+ return {
1664
+ name: rec.name,
1665
+ keywords: keywordsOf(integrationMemberEntry(loaded, rec) ?? loaded),
1666
+ };
1667
+ }),
1251
1668
  );
1252
1669
  });
1253
1670
  return [
@@ -1421,6 +1838,10 @@ async function gatherDocs(cwd) {
1421
1838
  ...defined,
1422
1839
  ...codeTerms({content}),
1423
1840
  ],
1841
+ _declared: [
1842
+ ...(Array.isArray(selfDoc?.keywords) ? selfDoc.keywords : []),
1843
+ ...(Array.isArray(node.keywords) ? node.keywords : []),
1844
+ ],
1424
1845
  description: node.summary || '',
1425
1846
  prose: sectionProse({title: node.title, content}),
1426
1847
  titles: [node.title],
@@ -1557,6 +1978,7 @@ function topicCandidates(
1557
1978
  ...(doc?.title || title ? [doc?.title || title] : []),
1558
1979
  ...(Array.isArray(doc?.keywords) ? doc.keywords : []),
1559
1980
  ],
1981
+ _declared: Array.isArray(doc?.keywords) ? doc.keywords : [],
1560
1982
  description: doc?.description || summary,
1561
1983
  prose: split
1562
1984
  ? sections.map(section => section.title).filter(Boolean)
@@ -1816,8 +2238,6 @@ async function searchOnce(query, options) {
1816
2238
  }
1817
2239
 
1818
2240
  const term = String(query).trim().toLowerCase();
1819
- const tokens = tokenizeQuery(term);
1820
-
1821
2241
  // `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
1822
2242
  // list` reads themes without it (bundled themes need no project), so a
1823
2243
  // search of either must too. Every other domain reads core: asked for by
@@ -1849,14 +2269,100 @@ async function searchOnce(query, options) {
1849
2269
 
1850
2270
  const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
1851
2271
 
2272
+ // A query that is one identifier counts as the words it spells
2273
+ // (`SidebarToggle`), and still matches whole as typed. In a query of several
2274
+ // words, each identifier stays one term (`ChatComposer ChatLayout` names two
2275
+ // components), and its words still join into names (see compoundHit). Both
2276
+ // only help a query that names no entry outright: when the query is an
2277
+ // entry's name, typed whole or as its words, that entry answers it, and
2278
+ // neither reading may add near siblings beside it.
2279
+ const spelled = spellIdentifiers(String(query).trim());
2280
+ const exact = all.some(candidate =>
2281
+ [candidate.name, ...(candidate.aliases ?? [])].some(name => {
2282
+ const lower = String(name).toLowerCase();
2283
+ return (
2284
+ lower === term ||
2285
+ (candidate.domain !== 'doc' &&
2286
+ !/[\s_-]/.test(lower) &&
2287
+ lower === term.replace(/\s+/g, ''))
2288
+ );
2289
+ }),
2290
+ );
2291
+ // One identifier is read as its words only when, read whole, it matches
2292
+ // nothing: a prop or hook name a doc already mentions keeps the
2293
+ // entries that mention it.
2294
+ const split =
2295
+ !exact &&
2296
+ !/\s/.test(term) &&
2297
+ spelled !== term &&
2298
+ !all.some(candidate => scoreCandidate(term, candidate));
2299
+ const tokens = tokenizeQuery(split ? spelled : term);
2300
+ /** @type {string[]} */
2301
+ const words = exact
2302
+ ? []
2303
+ : phraseWords(split || /\s/.test(term) ? spelled : term);
2304
+ // The entries the query names: a component, hook, or template whose whole
2305
+ // name is adjacent query words joined (`icon button in a card header` names
2306
+ // IconButton), or one identifier typed as such. A name inside a longer named
2307
+ // run does not count (`icon` there is part of IconButton).
2308
+ const queryWords = phraseWords(spelled);
2309
+ const typedIdentifiers = new Set(
2310
+ (String(query).match(/[A-Za-z0-9]+/g) ?? [])
2311
+ .filter(w => /[A-Z]/.test(w))
2312
+ .map(w => w.toLowerCase()),
2313
+ );
2314
+ /** @type {Map<string, [number, number]>} each run joined, longest first */
2315
+ const spans = new Map();
2316
+ for (let len = Math.min(queryWords.length, MAX_RUN_WORDS); len >= 1; len--) {
2317
+ for (let a = 0; a + len <= queryWords.length; a++) {
2318
+ // One plain word names too much (`list`, `field`); a named entry is a
2319
+ // run of joined words, or an identifier typed as one.
2320
+ if (len === 1 && !typedIdentifiers.has(queryWords[a])) continue;
2321
+ const run = queryWords.slice(a, a + len).join('');
2322
+ if (!spans.has(run)) spans.set(run, [a, a + len]);
2323
+ }
2324
+ }
2325
+ /**
2326
+ * Where a query word is the candidate's whole name, or null: such an entry
2327
+ * keeps the rank its name earns, whatever else it matched.
2328
+ * @param {Candidate} candidate
2329
+ * @returns {[number, number] | null}
2330
+ */
2331
+ const wordNamed = candidate => {
2332
+ if (candidate.domain === 'doc') return null;
2333
+ for (const name of [candidate.name, ...(candidate.aliases ?? [])]) {
2334
+ const n = joined(name);
2335
+ const at = queryWords.findIndex(w => w === n || w === `${n}s`);
2336
+ if (at >= 0) return [at, at + 1];
2337
+ }
2338
+ return null;
2339
+ };
2340
+ /** @param {Candidate} candidate @returns {[number, number] | null} */
2341
+ const namedSpan = candidate => {
2342
+ if (candidate.domain === 'doc') return null;
2343
+ /** @type {[number, number] | null} */
2344
+ let best = null;
2345
+ for (const name of [candidate.name, ...(candidate.aliases ?? [])]) {
2346
+ const n = joined(name);
2347
+ const span =
2348
+ spans.get(n) ??
2349
+ spans.get(`${n}s`) ??
2350
+ (/(?:s|x|z|ch|sh)$/.test(n) ? spans.get(`${n}es`) : undefined);
2351
+ if (span && (!best || span[1] - span[0] > best[1] - best[0])) {
2352
+ best = span;
2353
+ }
2354
+ }
2355
+ return best;
2356
+ };
2357
+
1852
2358
  // Score every candidate on its own merits. The consumer groups results by
1853
2359
  // role (page / block / component) and takes the top of each, so there's no
1854
2360
  // cross-role competition to engineer — a target page only needs to be the
1855
2361
  // strongest PAGE, not outrank every component.
1856
- /** @type {{result: any, priority: 0 | 1 | 2}[]} */
2362
+ /** @type {{result: any, priority: 0 | 1 | 2, key: number, alias: 'partial' | 'keyword' | false, aliasWords: number, candidate: Candidate, span: [number, number] | null, word: [number, number] | null}[]} */
1857
2363
  const ranked = [];
1858
2364
  for (const candidate of all) {
1859
- const hit = scoreQuery(term, tokens, candidate);
2365
+ const hit = scoreQuery(term, tokens, candidate, words);
1860
2366
  if (hit)
1861
2367
  ranked.push({
1862
2368
  result: toResult(
@@ -1866,9 +2372,54 @@ async function searchOnce(query, options) {
1866
2372
  hit.matched,
1867
2373
  hit.total,
1868
2374
  ),
1869
- priority: domainPriority(term, tokens, candidate, hit),
2375
+ priority: domainPriority(term, tokens, candidate, hit, words),
2376
+ key: hit.score,
2377
+ alias: hit.alias ?? false,
2378
+ aliasWords: hit.aliasWords ?? 0,
2379
+ candidate,
2380
+ span: namedSpan(candidate),
2381
+ word: wordNamed(candidate),
1870
2382
  });
1871
2383
  }
2384
+ // A match on a keyword read joined never outranks an entry the query names,
2385
+ // and neither does a match on part of another name unless it spans more
2386
+ // query words than any named run: `table header with sticky columns` keeps
2387
+ // TableHeader above useTableStickyColumns, which only holds the words
2388
+ // `sticky columns`. Only the order changes; each result keeps the score its
2389
+ // text earned.
2390
+ /** @param {[number, number]} inner @param {[number, number]} outer */
2391
+ const inside = (inner, outer) =>
2392
+ outer[0] <= inner[0] &&
2393
+ outer[1] >= inner[1] &&
2394
+ outer[1] - outer[0] > inner[1] - inner[0];
2395
+ const named = ranked.filter(r => {
2396
+ const span = r.span;
2397
+ return (
2398
+ span != null &&
2399
+ !ranked.some(o => o !== r && o.span != null && inside(span, o.span))
2400
+ );
2401
+ });
2402
+ /** @param {{key: number}[]} rows */
2403
+ const floorOf = rows =>
2404
+ rows.length ? Math.min(...rows.map(r => r.key)) : Infinity;
2405
+ const namedFloor = floorOf(named);
2406
+ const longestNamed = Math.max(
2407
+ 0,
2408
+ ...named.map(r => (r.span ? r.span[1] - r.span[0] : 0)),
2409
+ );
2410
+ for (const r of ranked) {
2411
+ if (named.includes(r)) continue;
2412
+ if (!r.alias || r.word) continue;
2413
+ // A match on part of a longer name that spans more words than any named
2414
+ // run reads more of the query than the named entry does (`dropdown menu
2415
+ // radio` and DropdownMenuRadioItem, against DropdownMenu), so it is not
2416
+ // held back. A joined keyword always is.
2417
+ if (r.alias === 'partial' && r.aliasWords > longestNamed) continue;
2418
+ // It keeps what it earns without those matches.
2419
+ const own =
2420
+ scoreQuery(term, tokens, r.candidate, words, {plain: true})?.score ?? 0;
2421
+ r.key = Math.max(own, Math.min(r.key, namedFloor - 0.5));
2422
+ }
1872
2423
 
1873
2424
  // Docs and everything else are each sorted by score desc, then domain
1874
2425
  // (stable order), then name. The two are merged: at each step the stronger
@@ -1877,11 +2428,11 @@ async function searchOnce(query, options) {
1877
2428
  /** @type {Record<string, number>} */
1878
2429
  const domainOrder = {component: 0, hook: 1, doc: 2, template: 3, theme: 4};
1879
2430
  /**
1880
- * @param {{result: any}} x
1881
- * @param {{result: any}} y
2431
+ * @param {{result: any, key: number}} x
2432
+ * @param {{result: any, key: number}} y
1882
2433
  */
1883
- const byScore = ({result: a}, {result: b}) =>
1884
- b.score - a.score ||
2434
+ const byScore = ({result: a, key: ka}, {result: b, key: kb}) =>
2435
+ kb - ka ||
1885
2436
  (domainOrder[a.domain] ?? 9) - (domainOrder[b.domain] ?? 9) ||
1886
2437
  a.name.localeCompare(b.name);
1887
2438
  const others = ranked.filter(r => r.result.domain !== 'doc').sort(byScore);