@astryxdesign/cli 0.7.2-canary.7462c41 → 0.7.2-canary.7ae39ea

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 (111) hide show
  1. package/README.md +6 -6
  2. package/api/doctor/doctor.mjs +27 -3
  3. package/api/doctor/doctor.test.mjs +43 -0
  4. package/api/integration/integrationComponentConflicts.doc.mjs +9 -3
  5. package/api/integration/validateIntegration.doc.mjs +3 -1
  6. package/api/search/search.d.mts +59 -6
  7. package/api/search/search.domain-priority.test.mjs +15 -0
  8. package/api/search/search.mjs +468 -28
  9. package/api/search/search.test.mjs +139 -0
  10. package/assets/docs/styling-overview.doc.mjs +1 -1
  11. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  12. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  13. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  14. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  15. package/assets/docs/tree/block-template.doc.mjs +6 -18
  16. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  17. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  18. package/assets/docs/tree/check-your-docs.doc.mjs +10 -5
  19. package/assets/docs/tree/checks.doc.mjs +3 -3
  20. package/assets/docs/tree/codemods.doc.mjs +4 -4
  21. package/assets/docs/tree/component-family.doc.mjs +3 -5
  22. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  23. package/assets/docs/tree/components.doc.mjs +1 -1
  24. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -18
  25. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  26. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  27. package/assets/docs/tree/docs.doc.mjs +3 -3
  28. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  29. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  30. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  31. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  32. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  33. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  34. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  35. package/assets/docs/tree/integrations.doc.mjs +4 -0
  36. package/assets/docs/tree/links.doc.mjs +5 -4
  37. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  38. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  39. package/assets/docs/tree/migration.doc.mjs +0 -1
  40. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  41. package/assets/docs/tree/page-template.doc.mjs +3 -7
  42. package/assets/docs/tree/publishing.doc.mjs +1 -1
  43. package/assets/docs/tree/quick-start.doc.mjs +7 -19
  44. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  45. package/assets/docs/tree/replace-a-core-template.doc.mjs +5 -7
  46. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  47. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  48. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  49. package/assets/docs/tree/single-component.doc.mjs +12 -4
  50. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  51. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  52. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  53. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  54. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  55. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  56. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  57. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  58. package/assets/docs/tree/templates.doc.mjs +1 -1
  59. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  60. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  61. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  62. package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
  63. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  64. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  65. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  66. package/assets/docs/tree/versioning.doc.mjs +6 -6
  67. package/assets/docs/tree/write-the-template-file.doc.mjs +2 -2
  68. package/authoring/codemod/codemod.doc.mjs +7 -3
  69. package/authoring/config/config.doc.mjs +9 -6
  70. package/authoring/config/type.ts +4 -2
  71. package/authoring/discover/discover.doc.mjs +1 -1
  72. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  73. package/authoring/doctypes/command/command.doc.mjs +14 -12
  74. package/authoring/doctypes/component/component.doc.mjs +28 -25
  75. package/authoring/doctypes/component/type.ts +7 -5
  76. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  77. package/authoring/doctypes/function/function.doc.mjs +9 -8
  78. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  79. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  80. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  81. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  82. package/authoring/doctypes/template/template.doc.mjs +2 -2
  83. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  84. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  85. package/authoring/identity/identity.doc.mjs +3 -3
  86. package/authoring/integration/integration.doc.mjs +4 -3
  87. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  88. package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -1
  89. package/clients/cli/commands/doctor-integration-validate.doc.mjs +3 -1
  90. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  91. package/clients/cli/commands/swizzle.mjs +5 -3
  92. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  93. package/clients/cli/index.mjs +29 -5
  94. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  95. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  96. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  97. package/foundation/agent-docs/agent-docs.mjs +8 -6
  98. package/foundation/discovery/authoring-self-docs.mjs +1 -1
  99. package/foundation/discovery/doc-types.d.mts +1 -1
  100. package/foundation/discovery/doc-types.mjs +3 -3
  101. package/foundation/discovery/doc-types.test.mjs +48 -0
  102. package/foundation/discovery/project-typescript.d.mts +11 -2
  103. package/foundation/discovery/project-typescript.mjs +32 -4
  104. package/foundation/discovery/prop-drift.d.mts +1 -1
  105. package/foundation/discovery/prop-drift.mjs +2 -2
  106. package/foundation/discovery/prop-drift.test.mjs +55 -2
  107. package/foundation/discovery/type-text.mjs +1 -1
  108. package/foundation/discovery/type-text.test.mjs +1 -1
  109. package/foundation/doc-compiler/doc-loads.test.mjs +6 -2
  110. package/package.json +9 -9
  111. package/scripts/postinstall.mjs +3 -3
@@ -259,9 +259,34 @@ function wordForms(w) {
259
259
  if (w.length > 3 && w.endsWith('s')) forms.add(w.slice(0, -1));
260
260
  if (w.length > 4 && w.endsWith('es')) forms.add(w.slice(0, -2));
261
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
+ }
262
272
  return forms;
263
273
  }
264
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
+
265
290
  /**
266
291
  * Whether two lowercase words are the same word, up to plural and stem form.
267
292
  * @param {string} a
@@ -302,9 +327,201 @@ function wordsOf(text) {
302
327
  function startsAWordOf(term, text) {
303
328
  if (term.length < 4) return false;
304
329
  if (term.length / String(text).length < 0.5) return false;
305
- return wordsOf(text).some(w => w.startsWith(term) || sameWord(term, w));
330
+ // The term or its singular may start the word: "tokens" starts
331
+ // "tokenizer" through "token". A singular needs five letters, so "stats"
332
+ // does not start "status".
333
+ const starts = [term, ...singulars(term).filter(f => f.length >= 5)];
334
+ return wordsOf(text).some(
335
+ w => starts.some(f => w.startsWith(f)) || sameWord(term, w),
336
+ );
337
+ }
338
+
339
+ /**
340
+ * A query with its camelCase and PascalCase identifiers spelled as words, so
341
+ * `SidebarToggle` reads "sidebar toggle" and `useTablePaginationState` "use
342
+ * table pagination state". Plain words, and identifiers joined with `_` or `-`, are
343
+ * unchanged: a joined token that matches nothing stays unmatched.
344
+ * @param {string} query - The query as typed, before lowercasing.
345
+ * @returns {string} Lowercased.
346
+ */
347
+ export function spellIdentifiers(query) {
348
+ return String(query)
349
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
350
+ .replace(/([A-Z])([A-Z][a-z])/g, '$1 $2')
351
+ .toLowerCase();
352
+ }
353
+
354
+ /**
355
+ * A name or keyword with its separators removed, lowercased: `Side Nav`,
356
+ * `side-nav`, and `SideNav` all join to `sidenav`.
357
+ * @param {string} text
358
+ * @returns {string}
359
+ */
360
+ function joined(text) {
361
+ return String(text)
362
+ .toLowerCase()
363
+ .replace(/[^a-z0-9]+/g, '');
364
+ }
365
+
366
+ /**
367
+ * The strongest hit a run of two or more adjacent query words has when it is
368
+ * read as one joined word, and the query words it covers. Readers type a
369
+ * compound name as separate words (`table header cell` is TableHeaderCell,
370
+ * `number field` the keyword `numberfield`), and no single word of the run
371
+ * matches on its own.
372
+ *
373
+ * - 100: the run joins to a component, hook, or template name, or its plural
374
+ * (`table header cells` is TableHeaderCell), or a hook name without its
375
+ * `use` prefix (`table sticky columns` is useTableStickyColumns).
376
+ * - 90: the run joins to a one-word keyword (`number field` is
377
+ * `numberfield`).
378
+ * - 95: the run joins to most of a name, cut short (`dropdown menu radio` is
379
+ * DropdownMenuRadioItem); 92: it is a name's leading words, covering at least half
380
+ * of it (`top nav mega` is TopNavMegaMenu); 70: it is two or more adjacent
381
+ * words of a name that cover at least half of it (`header cell` in
382
+ * TableHeaderCell), the same coverage a word prefix needs. These three
383
+ * are for components and hooks only.
384
+ *
385
+ * A doc's name is a route or key, so docs are left out.
386
+ * @param {string[]} words - The query's words, stopwords included.
387
+ * @param {Candidate} candidate
388
+ * @returns {{score: number, reason: string, covered: Set<string>, alias?: '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;
306
516
  }
307
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
+
308
525
  /**
309
526
  * The fewest letters both words need before an edit distance counts as a
310
527
  * typo, by distance. Below them, one edit usually makes a different word.
@@ -541,7 +758,13 @@ const STRONG_TOKEN_SCORE = 70;
541
758
  * candidate's scoreQuery result.
542
759
  * @returns {0 | 1 | 2}
543
760
  */
544
- export function domainPriority(term, tokens, candidate, hit) {
761
+ export function domainPriority(
762
+ term,
763
+ tokens,
764
+ candidate,
765
+ hit,
766
+ queryWords = phraseWords(term),
767
+ ) {
545
768
  const words = [term, ...tokens];
546
769
  if (candidate.domain === 'doc') {
547
770
  const topic = String(candidate._topic ?? candidate.name).toLowerCase();
@@ -600,6 +823,12 @@ export function domainPriority(term, tokens, candidate, hit) {
600
823
  return 0;
601
824
  }
602
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
+ }
603
832
  const fuzzy = tokens.length <= 1;
604
833
  return words.some(
605
834
  w =>
@@ -715,14 +944,24 @@ export function titleInQuery(term, titles) {
715
944
  * @param {string} term - Lowercased full query.
716
945
  * @param {string[]} tokens - Content tokens from tokenizeQuery(term).
717
946
  * @param {Candidate} candidate
718
- * @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}
719
952
  * `matched`/`total` are the query concepts this candidate answered, out of
720
953
  * the concepts the query had. Callers that must distinguish "matched one word
721
954
  * of three" from "matched all three" — `build`, which gates its pages group
722
955
  * on coverage — cannot recover that from the score, because a single strong
723
956
  * hit and a broad weak one land on the same number.
724
957
  */
725
- export function scoreQuery(term, tokens, candidate) {
958
+ export function scoreQuery(
959
+ term,
960
+ tokens,
961
+ candidate,
962
+ words = phraseWords(term),
963
+ {plain = false} = {},
964
+ ) {
726
965
  const total = Math.max(tokens.length, 1);
727
966
  // A whole-phrase hit answered the whole query by definition.
728
967
  const asFull = (/** @type {{score: number, reason: string}} */ hit) => ({
@@ -731,14 +970,24 @@ export function scoreQuery(term, tokens, candidate) {
731
970
  total,
732
971
  });
733
972
  // Typo tolerance is for one-word lookups. In a multi-word query a near miss
734
- // is usually a different word, not a typo.
735
- const fuzzy = tokens.length <= 1;
736
- 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
+ });
737
980
  // A query of several words keeps its phrase tiers below even when stopwords
738
981
  // leave one content word: "make an integration" is still the phrase an
739
982
  // author declares as a keyword, and "build an integration" still names a
740
983
  // title outright, though each tokenizes to `integration` alone.
741
- 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
+ }
742
991
 
743
992
  /** 0–1 content tokens: whole-phrase fuzzy matching (typo tolerance for
744
993
  * single words), but if stopwords left exactly one DIFFERENT token (e.g.
@@ -763,7 +1012,11 @@ export function scoreQuery(term, tokens, candidate) {
763
1012
  // of Table-related templates each match "table" and "contents" separately
764
1013
  // and accumulate a higher raw score (#5239).
765
1014
  if (full && full.score >= 90) {
766
- 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
+ });
767
1020
  }
768
1021
 
769
1022
  // The whole query standing as a phrase in a doc's title or one of its
@@ -789,8 +1042,25 @@ export function scoreQuery(term, tokens, candidate) {
789
1042
  let tokenSum = 0;
790
1043
  /** @type {string[]} */
791
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;
792
1052
  for (const tok of tokens) {
793
- 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
+ }
794
1064
  if (h && h.score >= MIN_TOKEN_SCORE) {
795
1065
  if (h.score > strongest) strongest = h.score;
796
1066
  matched++;
@@ -840,6 +1110,7 @@ export function scoreQuery(term, tokens, candidate) {
840
1110
  reason,
841
1111
  matched,
842
1112
  total,
1113
+ ...(alias ? {alias, aliasWords} : {}),
843
1114
  };
844
1115
  }
845
1116
 
@@ -865,7 +1136,13 @@ export function scoreQuery(term, tokens, candidate) {
865
1136
  strongest + Math.min(matched - 1, 3) * 12 + coverage * 15,
866
1137
  );
867
1138
  if (full && full.score >= tokenScore) return asFull(full);
868
- return {score: tokenScore, reason, matched, total};
1139
+ return {
1140
+ score: tokenScore,
1141
+ reason,
1142
+ matched,
1143
+ total,
1144
+ ...(alias ? {alias, aliasWords} : {}),
1145
+ };
869
1146
  }
870
1147
 
871
1148
  /**
@@ -884,8 +1161,9 @@ export function scoreQuery(term, tokens, candidate) {
884
1161
  * @param {string} [candidate.description]
885
1162
  * @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
886
1163
  * @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
887
- * @param {{fuzzy?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false.
888
- * @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.
889
1167
  */
890
1168
  export function scoreCandidate(
891
1169
  term,
@@ -899,18 +1177,23 @@ export function scoreCandidate(
899
1177
  prose = [],
900
1178
  guidance = [],
901
1179
  },
902
- {fuzzy = true} = {},
1180
+ {fuzzy = true, joins = true} = {},
903
1181
  ) {
904
1182
  let best = 0;
905
1183
  let reason = '';
1184
+ /** @type {'partial' | 'keyword' | false} */
1185
+ let alias = false;
906
1186
  /**
907
1187
  * @param {number} score
908
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
909
1191
  */
910
- const consider = (score, why) => {
1192
+ const consider = (score, why, byAlias = false) => {
911
1193
  if (score > best) {
912
1194
  best = score;
913
1195
  reason = why;
1196
+ alias = byAlias;
914
1197
  }
915
1198
  };
916
1199
 
@@ -934,6 +1217,16 @@ export function scoreCandidate(
934
1217
  nameLower === term.replace(/\s+/g, '');
935
1218
  if (nameLower === term || leafLower === term || spelled) {
936
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');
937
1230
  } else if (pluralOf(nameLower, term) || pluralOf(term, nameLower)) {
938
1231
  // One point under the exact spelling, so the doc named `tokens` still
939
1232
  // outranks the Token component for `tokens`.
@@ -957,12 +1250,27 @@ export function scoreCandidate(
957
1250
  }
958
1251
 
959
1252
  // ── Keyword signals ─────────────────────────────────────────────
1253
+ const termJoined = joined(term);
960
1254
  for (const kw of keywords) {
961
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.
962
1261
  if (kwLower === term) {
963
1262
  consider(90, `keyword "${kw}"`);
964
1263
  continue;
965
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
+ }
966
1274
  if (sameWord(term, kwLower)) {
967
1275
  consider(88, `keyword "${kw}"`);
968
1276
  continue;
@@ -994,9 +1302,12 @@ export function scoreCandidate(
994
1302
  // Match the term's stem as a whole word, tolerating plural/gerund suffixes
995
1303
  // so "chart" matches "charts" and "filter" matches "filtering".
996
1304
  if (term.length >= 3) {
997
- const root = stem(term);
998
- const escaped = root.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
999
- 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`);
1000
1311
  if (description && re.test(description.toLowerCase())) {
1001
1312
  consider(50, `description mentions "${term}"`);
1002
1313
  } else {
@@ -1022,7 +1333,7 @@ export function scoreCandidate(
1022
1333
  }
1023
1334
  }
1024
1335
 
1025
- return best > 0 ? {score: best, reason} : null;
1336
+ return best > 0 ? {score: best, reason, ...(alias ? {alias} : {})} : null;
1026
1337
  }
1027
1338
 
1028
1339
  /**
@@ -1927,8 +2238,6 @@ async function searchOnce(query, options) {
1927
2238
  }
1928
2239
 
1929
2240
  const term = String(query).trim().toLowerCase();
1930
- const tokens = tokenizeQuery(term);
1931
-
1932
2241
  // `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
1933
2242
  // list` reads themes without it (bundled themes need no project), so a
1934
2243
  // search of either must too. Every other domain reads core: asked for by
@@ -1960,14 +2269,100 @@ async function searchOnce(query, options) {
1960
2269
 
1961
2270
  const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
1962
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
+
1963
2358
  // Score every candidate on its own merits. The consumer groups results by
1964
2359
  // role (page / block / component) and takes the top of each, so there's no
1965
2360
  // cross-role competition to engineer — a target page only needs to be the
1966
2361
  // strongest PAGE, not outrank every component.
1967
- /** @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}[]} */
1968
2363
  const ranked = [];
1969
2364
  for (const candidate of all) {
1970
- const hit = scoreQuery(term, tokens, candidate);
2365
+ const hit = scoreQuery(term, tokens, candidate, words);
1971
2366
  if (hit)
1972
2367
  ranked.push({
1973
2368
  result: toResult(
@@ -1977,9 +2372,54 @@ async function searchOnce(query, options) {
1977
2372
  hit.matched,
1978
2373
  hit.total,
1979
2374
  ),
1980
- 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),
1981
2382
  });
1982
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
+ }
1983
2423
 
1984
2424
  // Docs and everything else are each sorted by score desc, then domain
1985
2425
  // (stable order), then name. The two are merged: at each step the stronger
@@ -1988,11 +2428,11 @@ async function searchOnce(query, options) {
1988
2428
  /** @type {Record<string, number>} */
1989
2429
  const domainOrder = {component: 0, hook: 1, doc: 2, template: 3, theme: 4};
1990
2430
  /**
1991
- * @param {{result: any}} x
1992
- * @param {{result: any}} y
2431
+ * @param {{result: any, key: number}} x
2432
+ * @param {{result: any, key: number}} y
1993
2433
  */
1994
- const byScore = ({result: a}, {result: b}) =>
1995
- b.score - a.score ||
2434
+ const byScore = ({result: a, key: ka}, {result: b, key: kb}) =>
2435
+ kb - ka ||
1996
2436
  (domainOrder[a.domain] ?? 9) - (domainOrder[b.domain] ?? 9) ||
1997
2437
  a.name.localeCompare(b.name);
1998
2438
  const others = ranked.filter(r => r.result.domain !== 'doc').sort(byScore);