@astryxdesign/cli 0.7.2-canary.ba80461 → 0.7.2-canary.bd72a5f

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