@astryxdesign/cli 0.7.17 → 0.7.18-canary.g6dfc0b6

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 (213) hide show
  1. package/README.md +1 -1
  2. package/api/discover/_adapter.d.mts +7 -5
  3. package/api/discover/_adapter.mjs +12 -11
  4. package/api/doctor/_adapter.d.mts +11 -62
  5. package/api/doctor/_adapter.mjs +242 -472
  6. package/api/doctor/doctor.d.mts +1 -1
  7. package/api/doctor/doctor.mjs +1 -1
  8. package/api/doctor/theme-checks.mjs +37 -45
  9. package/api/error.d.mts +21 -0
  10. package/api/error.mjs +89 -0
  11. package/api/hook/list/list.d.mts +1 -1
  12. package/api/icon/icon.doc.mjs +1 -1
  13. package/api/icon/icon.type.mjs +1 -1
  14. package/api/icon/search/search.d.mts +4 -1
  15. package/api/icon/search/search.mjs +41 -4
  16. package/api/render/_adapter.mjs +233 -40
  17. package/api/render/render.type.d.mts +1 -1
  18. package/api/render/render.type.mjs +1 -1
  19. package/api/search/ORDERING.md +2 -2
  20. package/api/search/_candidate-score.mjs +32 -8
  21. package/api/search/_cards.json +1 -1
  22. package/api/search/_compound.d.mts +0 -1
  23. package/api/search/_compound.mjs +93 -2
  24. package/api/search/_lexical.mjs +177 -17
  25. package/api/search/_order.d.mts +3 -1
  26. package/api/search/_order.mjs +16 -5
  27. package/api/search/_result.d.mts +9 -0
  28. package/api/search/_result.mjs +10 -0
  29. package/api/search/_score.mjs +21 -3
  30. package/api/swizzle/_moduleGraph.d.mts +8 -0
  31. package/api/swizzle/_moduleGraph.mjs +61 -3
  32. package/api/template/copy/copy.mjs +5 -3
  33. package/api/theme/_adapter.mjs +48 -12
  34. package/api/theme/build/build.d.mts +4 -0
  35. package/api/theme/build/build.mjs +69 -18
  36. package/api/theme/build/style-keys.mjs +4 -5
  37. package/api/theme/build/theme-object.mjs +5 -0
  38. package/api/theme/palette/generate/color.d.mts +47 -0
  39. package/api/theme/palette/generate/color.mjs +58 -1
  40. package/api/theme/palette/generate/derive-look.d.mts +293 -0
  41. package/api/theme/palette/generate/derive-look.mjs +1362 -0
  42. package/api/theme/palette/generate/editor-look.d.mts +62 -0
  43. package/api/theme/palette/generate/editor-look.mjs +550 -0
  44. package/api/theme/palette/generate/mapping.d.mts +94 -9
  45. package/api/theme/palette/generate/mapping.mjs +94 -22
  46. package/api/theme-edit/_adapter.mjs +10 -1
  47. package/api/theme-edit/_catalog.d.mts +13 -13
  48. package/api/theme-edit/_catalog.mjs +38 -16
  49. package/api/theme-edit/_check.d.mts +82 -6
  50. package/api/theme-edit/_check.mjs +1230 -223
  51. package/api/theme-edit/_color.d.mts +74 -0
  52. package/api/theme-edit/_color.mjs +168 -3
  53. package/api/theme-edit/_compiler.d.mts +3 -5
  54. package/api/theme-edit/_compiler.mjs +122 -23
  55. package/api/theme-edit/_context.d.mts +46 -5
  56. package/api/theme-edit/_context.mjs +97 -49
  57. package/api/theme-edit/_css.d.mts +11 -0
  58. package/api/theme-edit/_css.mjs +40 -0
  59. package/api/theme-edit/_edit.d.mts +13 -0
  60. package/api/theme-edit/_edit.mjs +1450 -128
  61. package/api/theme-edit/_how-commands.d.mts +12 -0
  62. package/api/theme-edit/_how-commands.mjs +96 -14
  63. package/api/theme-edit/_how-question.d.mts +73 -29
  64. package/api/theme-edit/_how-question.mjs +8131 -1209
  65. package/api/theme-edit/_how-sides.d.mts +22 -0
  66. package/api/theme-edit/_how-sides.mjs +173 -0
  67. package/api/theme-edit/_how-steps.d.mts +42 -0
  68. package/api/theme-edit/_how-steps.mjs +208 -0
  69. package/api/theme-edit/_how-values.d.mts +29 -0
  70. package/api/theme-edit/_how-values.mjs +111 -0
  71. package/api/theme-edit/_how-words.d.mts +15 -0
  72. package/api/theme-edit/_how-words.mjs +239 -0
  73. package/api/theme-edit/_how.d.mts +1 -1
  74. package/api/theme-edit/_how.mjs +412 -37
  75. package/api/theme-edit/_missed.d.mts +2 -1
  76. package/api/theme-edit/_missed.mjs +125 -13
  77. package/api/theme-edit/_normal.d.mts +5 -3
  78. package/api/theme-edit/_normal.mjs +54 -14
  79. package/api/theme-edit/_palette.d.mts +204 -4
  80. package/api/theme-edit/_palette.mjs +901 -25
  81. package/api/theme-edit/_part-pieces.d.mts +54 -0
  82. package/api/theme-edit/_part-pieces.mjs +179 -0
  83. package/api/theme-edit/_part-words.mjs +33 -5
  84. package/api/theme-edit/_parts.d.mts +133 -0
  85. package/api/theme-edit/_parts.mjs +599 -10
  86. package/api/theme-edit/_picture-traits.d.mts +259 -0
  87. package/api/theme-edit/_picture-traits.mjs +1030 -0
  88. package/api/theme-edit/_preview.d.mts +84 -4
  89. package/api/theme-edit/_preview.mjs +260 -24
  90. package/api/theme-edit/_project.d.mts +14 -4
  91. package/api/theme-edit/_project.mjs +95 -26
  92. package/api/theme-edit/_set-line.d.mts +29 -0
  93. package/api/theme-edit/_set-line.mjs +100 -0
  94. package/api/theme-edit/_settings.d.mts +625 -28
  95. package/api/theme-edit/_settings.mjs +4587 -880
  96. package/api/theme-edit/_tables.d.mts +25 -1
  97. package/api/theme-edit/_tables.mjs +115 -11
  98. package/api/theme-edit/_text-looks.d.mts +78 -0
  99. package/api/theme-edit/_text-looks.mjs +376 -0
  100. package/api/theme-edit/_vet.d.mts +3 -26
  101. package/api/theme-edit/_vet.mjs +5 -89
  102. package/api/theme-edit/how/how.d.mts +1 -1
  103. package/api/theme-edit/how/how.mjs +1 -1
  104. package/api/theme-edit/theme-edit.type.d.mts +54 -1
  105. package/api/theme-edit/theme-edit.type.mjs +17 -2
  106. package/api/theme-edit/themeEditHow.doc.mjs +3 -3
  107. package/api/theme-edit/themeEditNew.doc.mjs +4 -0
  108. package/api/theme-edit/themeEditSet.doc.mjs +6 -2
  109. package/api/theme-edit/themeEditShow.doc.mjs +4 -0
  110. package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
  111. package/assets/component-list.generated.json +1 -1
  112. package/assets/docs/author-a-theme.doc.mjs +7 -4
  113. package/assets/docs/tree/export-pages.doc.mjs +1 -1
  114. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  115. package/assets/docs/use-a-theme.doc.mjs +89 -17
  116. package/assets/docs-routes.generated.json +1 -1
  117. package/assets/docs.generated.json +2 -2
  118. package/assets/icons/definitions/article.doc.mjs +9 -0
  119. package/assets/icons/template-icons.json +5 -0
  120. package/assets/search-catalog.generated.json +2 -2
  121. package/assets/self-audit.generated.json +1 -1
  122. package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
  123. package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
  124. package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
  125. package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
  126. package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
  127. package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
  128. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
  129. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
  130. package/assets/templates/components.generated.json +1 -1
  131. package/assets/templates/pages/ide/page.tsx +5 -10
  132. package/assets/templates/pages/payment-form/page.tsx +16 -60
  133. package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
  134. package/authoring/debug/parse.d.mts +1 -1
  135. package/authoring/doctypes/_schema.d.mts +13 -13
  136. package/authoring/gap-report/parse.d.mts +1 -1
  137. package/clients/cli/build-id.generated.json +1 -1
  138. package/clients/cli/commands/ensure-core-built.mjs +17 -10
  139. package/clients/cli/commands/experimental/theme.mjs +46 -6
  140. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  142. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
  143. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
  144. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  145. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  146. package/clients/cli/commands/hook.mjs +7 -0
  147. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  148. package/clients/cli/index.mjs +6 -2
  149. package/clients/cli/lib/hook-format.mjs +41 -1
  150. package/clients/cli/lib/json-shim.mjs +34 -14
  151. package/clients/cli/lib/other-cli-words.mjs +7 -0
  152. package/clients/cli/lib/unknown-command.mjs +345 -46
  153. package/clients/cli/manifest.generated.json +1 -1
  154. package/foundation/agent-docs/agent-docs.d.mts +11 -2
  155. package/foundation/agent-docs/agent-docs.mjs +51 -8
  156. package/foundation/config/project.d.mts +11 -1
  157. package/foundation/config/project.mjs +11 -2
  158. package/foundation/discovery/component-replacement.d.mts +5 -8
  159. package/foundation/discovery/component-replacement.mjs +12 -14
  160. package/foundation/discovery/core-augmentation-points.d.mts +35 -0
  161. package/foundation/discovery/core-augmentation-points.mjs +410 -9
  162. package/foundation/discovery/core-elements.d.mts +6 -0
  163. package/foundation/discovery/core-elements.mjs +10 -2
  164. package/foundation/discovery/core-prop-types.d.mts +5 -0
  165. package/foundation/discovery/core-prop-types.mjs +10 -3
  166. package/foundation/discovery/core-props.d.mts +8 -0
  167. package/foundation/discovery/core-props.mjs +29 -13
  168. package/foundation/discovery/official-list.d.mts +17 -0
  169. package/foundation/discovery/official-list.mjs +77 -0
  170. package/foundation/discovery/unknown-core-props.d.mts +130 -0
  171. package/foundation/discovery/unknown-core-props.mjs +601 -0
  172. package/foundation/discovery/written-prop-values.d.mts +35 -0
  173. package/foundation/discovery/written-prop-values.mjs +258 -0
  174. package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
  175. package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
  176. package/foundation/fs/package-name.d.mts +10 -0
  177. package/foundation/fs/package-name.mjs +37 -0
  178. package/foundation/fs/project-source-files.d.mts +27 -0
  179. package/foundation/fs/project-source-files.mjs +115 -0
  180. package/foundation/fs/project-sources.d.mts +25 -0
  181. package/foundation/fs/project-sources.mjs +83 -0
  182. package/foundation/fs/read-record.d.mts +18 -0
  183. package/foundation/fs/read-record.mjs +36 -2
  184. package/foundation/integrations/integration-warnings.d.mts +39 -7
  185. package/foundation/integrations/integration-warnings.mjs +141 -19
  186. package/foundation/integrations/missing-dependency.d.mts +11 -0
  187. package/foundation/integrations/missing-dependency.mjs +20 -5
  188. package/foundation/release/folder-lock.d.mts +5 -2
  189. package/foundation/release/folder-lock.mjs +9 -3
  190. package/foundation/release/notices.mjs +2 -8
  191. package/foundation/render/cut-short.d.mts +8 -2
  192. package/foundation/render/cut-short.mjs +50 -5
  193. package/foundation/render/drawn-contrast.d.mts +38 -0
  194. package/foundation/render/drawn-contrast.mjs +237 -0
  195. package/foundation/render/file-header.mjs +4 -0
  196. package/foundation/render/layers.d.mts +2 -1
  197. package/foundation/render/layers.mjs +22 -1
  198. package/foundation/render/page-worker.mjs +83 -18
  199. package/foundation/render/part-boxes.d.mts +27 -0
  200. package/foundation/render/part-boxes.mjs +45 -0
  201. package/foundation/render/picture-chrome.mjs +36 -4
  202. package/foundation/render/picture-playwright.mjs +26 -2
  203. package/foundation/render/picture-window.d.mts +29 -2
  204. package/foundation/render/picture-window.mjs +99 -1
  205. package/foundation/render/render-page.d.mts +39 -6
  206. package/foundation/render/render-page.mjs +26 -10
  207. package/foundation/render/ts-paths.mjs +2 -1
  208. package/foundation/response/error-codes.doc.mjs +1 -1
  209. package/foundation/response/error-codes.mjs +1 -1
  210. package/foundation/response/response-types.doc.mjs +1 -1
  211. package/foundation/text/written-string.d.mts +4 -1
  212. package/foundation/text/written-string.mjs +4 -1
  213. package/package.json +8 -7
@@ -53,9 +53,14 @@
53
53
  */
54
54
 
55
55
  import {spellIdentifiers, joined, sameWord, typoDistance} from './_words.mjs';
56
- import {tokenizeQuery, phraseWords, pluralOf} from './_query.mjs';
56
+ import {
57
+ tokenizeQuery,
58
+ phraseWords,
59
+ pluralOf,
60
+ samePhraseWord,
61
+ } from './_query.mjs';
57
62
  import {MAX_RUN_WORDS} from './_compound.mjs';
58
- import {scoreQuery} from './_score.mjs';
63
+ import {scoreQuery, STRONG_TOKEN_SCORE} from './_score.mjs';
59
64
  import {heldTitle} from './_titles.mjs';
60
65
  import {scoreCandidate} from './_candidate-score.mjs';
61
66
  import {domainPriority} from './_priority.mjs';
@@ -64,12 +69,22 @@ import {
64
69
  searchedComponentsOf,
65
70
  namedLeadsOf,
66
71
  rootLeadsOf,
72
+ weakRootsOf,
67
73
  answeredTerms,
68
74
  } from './_result.mjs';
69
- import {nameWords} from './_query-words.mjs';
75
+ import {fold, nameWords} from './_query-words.mjs';
70
76
  import {compareText} from '../../foundation/text/compare-text.mjs';
71
77
  import {COMPONENT_NAME_RE} from '../../foundation/text/entry-names.mjs';
72
78
 
79
+ /**
80
+ * The fewest words a name needs for the query to name it by writing its words
81
+ * apart (see spelledOut in rankLexical). Two words apart read as plain
82
+ * language (`multiline text input` asks for no TextInput, `alert dialog` may
83
+ * ask for either), so only a longer name, which plain language rarely spells
84
+ * out whole, counts.
85
+ */
86
+ const SPELLED_NAME_WORDS = 3;
87
+
73
88
  /**
74
89
  * A search candidate gathered from one content domain. Extra underscore-
75
90
  * prefixed fields carry domain-specific payload used only by {@link toResult}.
@@ -332,6 +347,56 @@ export function rankLexical(query, options, catalog) {
332
347
  return best;
333
348
  };
334
349
 
350
+ /**
351
+ * Where the query spells out the candidate's whole name of
352
+ * SPELLED_NAME_WORDS or more words as words apart (see spelledOut below),
353
+ * or null; the longest of its names. A doc page goes by its route's last
354
+ * part, as in namedSpan.
355
+ * @param {Candidate} candidate
356
+ * @returns {[number, number] | null}
357
+ */
358
+ const spelledSpan = candidate => {
359
+ const doc = candidate.domain === 'doc';
360
+ if (doc && candidate._topic != null && candidate._topic !== candidate.name)
361
+ return null;
362
+ const route = String(candidate.name);
363
+ const names = doc
364
+ ? [route.slice(route.lastIndexOf('/') + 1)]
365
+ : [candidate.name, ...(candidate.aliases ?? [])];
366
+ /** @type {[number, number] | null} */
367
+ let best = null;
368
+ for (const name of names) {
369
+ const words = phraseWords(spellIdentifiers(String(name)));
370
+ if (words.length < SPELLED_NAME_WORDS) continue;
371
+ if (best && best[1] - best[0] >= words.length) continue;
372
+ for (let a = 0; a + words.length <= queryWords.length; a++) {
373
+ const b = a + words.length;
374
+ const run = queryWords.slice(a, b);
375
+ // Every word stands as written (a plural on any), except at most one,
376
+ // which keeps its first letter, and the run read joined is a typo of
377
+ // the name joined as the scorer reads a misspelled name
378
+ // (typoDistance): `with` never stands in for `dot`, nor `list` for
379
+ // `ghost`.
380
+ const typos = words.flatMap((word, n) =>
381
+ samePhraseWord(run[n], word) ? [] : [n],
382
+ );
383
+ if (
384
+ typedAs[a - 1] === typedAs[a] ||
385
+ typedAs[b] === typedAs[b - 1] ||
386
+ typedAs[a] === typedAs[b - 1] ||
387
+ typos.length > 1 ||
388
+ typos.some(n => run[n][0] !== words[n][0]) ||
389
+ (typos.length === 1 &&
390
+ typoDistance(run.join(''), words.join('')) === null)
391
+ )
392
+ continue;
393
+ best = [a, b];
394
+ break;
395
+ }
396
+ }
397
+ return best;
398
+ };
399
+
335
400
  // In search's reading (`ownEvidence`, set by searchView), the query words
336
401
  // that name a component or hook outright (its whole name, as `namedSpan`
337
402
  // and `wordNamed` read it) and no doc. Such a word asks for that entry, and
@@ -376,7 +441,7 @@ export function rankLexical(query, options, catalog) {
376
441
  // role (page / block / component) and takes the top of each, so there's no
377
442
  // cross-role competition to engineer — a target page only needs to be the
378
443
  // strongest PAGE, not outrank every component.
379
- /** @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}[]} */
444
+ /** @type {{result: any, priority: 0 | 1 | 2, key: number, alias: 'partial' | 'keyword' | false, aliasWords: number, candidate: Candidate, hits: Map<string, {fuzzy: boolean, hit: {score: number, reason: string} | null}>, span: [number, number] | null, word: [number, number] | null}[]} */
380
445
  const ranked = [];
381
446
  for (const candidate of all) {
382
447
  // What scoreQuery scored each token as, for domainPriority below.
@@ -423,6 +488,7 @@ export function rankLexical(query, options, catalog) {
423
488
  alias: hit.alias ?? false,
424
489
  aliasWords: hit.aliasWords ?? 0,
425
490
  candidate,
491
+ hits: tokenHits,
426
492
  span: namedSpan(candidate),
427
493
  word: wordNamed(candidate),
428
494
  });
@@ -563,14 +629,36 @@ export function rankLexical(query, options, catalog) {
563
629
  const typedNamed = typed.filter(
564
630
  ({span}) => !runs.some(run => inside(span, run)),
565
631
  );
632
+ // In search's reading, an entry whose whole name of SPELLED_NAME_WORDS or
633
+ // more words the query spells out as words apart leads its run of matches
634
+ // (_order.mjs): the run's words are the name's words in order (a plural on
635
+ // any), at most one of them misspelled with its first letter kept, as the
636
+ // scorer reads a misspelled name: `glim tray sortde rows` for
637
+ // GlimTraySortedRows. Such a run names the entry more fully than a
638
+ // component that holds only its first words, or than its family's root. Two words apart stay plain language (see above). It leads
639
+ // only its run: it moves first among the matches scored the same and is
640
+ // first in its band, never past a match of another band.
641
+ const spelledOut = (catalog.ownEvidence ? ranked : []).flatMap(r => {
642
+ const span = spelledSpan(r.candidate);
643
+ return span ? [{r, span}] : [];
644
+ });
645
+ // A name inside a longer named run, spelled out or joined, names less of
646
+ // the query than that run: the longest wins.
647
+ const longer = [...runs, ...spelledOut.map(({span}) => span)];
648
+ const spelledNamed = spelledOut.filter(
649
+ ({r, span}) =>
650
+ !typedNamed.some(t => t.r === r) &&
651
+ !longer.some(run => inside(span, run)),
652
+ );
566
653
  // A longer name of another entry the query holds, a block's display name or
567
654
  // a doc's title or heading (`ChatComposerInput — Controlled`), names that
568
655
  // entry more fully, so the name inside it does not lead. It is held as the
569
656
  // title tier holds a title (heldTitle), with the query's identifiers spelled
570
- // out on both sides.
571
- /** @type {[number, number][]} */
657
+ // out on both sides. An entry's own display name or title does not stop
658
+ // its spelled-out name.
659
+ /** @type {{at: [number, number], of: Candidate}[]} */
572
660
  const labels = [];
573
- if (typedNamed.length) {
661
+ if (typedNamed.length || spelledNamed.length) {
574
662
  const spelledWords = (/** @type {string} */ text) =>
575
663
  phraseWords(spellIdentifiers(text));
576
664
  for (const candidate of all) {
@@ -579,17 +667,46 @@ export function rankLexical(query, options, catalog) {
579
667
  ...(candidate.titles ?? []),
580
668
  ]) {
581
669
  const held = heldTitle(queryWords, [label], spelledWords);
582
- if (held) labels.push(held.at);
670
+ if (held) labels.push({at: held.at, of: candidate});
583
671
  }
584
672
  }
585
673
  }
586
- const leads = new Set(
674
+ const typedLeads = new Set(
587
675
  typedNamed
588
- .filter(({span}) => !labels.some(label => inside(span, label)))
676
+ .filter(({span}) => !labels.some(label => inside(span, label.at)))
589
677
  .map(({r}) => r.result),
590
678
  );
591
- if (leads.size) {
592
- scored.sort((a, b) => Number(leads.has(b)) - Number(leads.has(a)));
679
+ const spelledLeads = spelledNamed
680
+ .filter(
681
+ ({r, span}) =>
682
+ !labels.some(
683
+ label => label.of !== r.candidate && inside(span, label.at),
684
+ ),
685
+ )
686
+ .map(({r}) => r.result);
687
+ // A part whose whole name the query spells out keeps its band lead over
688
+ // its family's root (rootLeads below).
689
+ const spelledLed = new Set(spelledLeads);
690
+ const leads = new Set([...typedLeads, ...spelledLeads]);
691
+ if (typedLeads.size) {
692
+ scored.sort(
693
+ (a, b) => Number(typedLeads.has(b)) - Number(typedLeads.has(a)),
694
+ );
695
+ }
696
+ // A spelled-out name goes first among the matches scored the same next to
697
+ // it, which move as one block in _order.mjs.
698
+ if (spelledLeads.length) {
699
+ const spelled = new Set(spelledLeads);
700
+ for (let a = 0; a < scored.length;) {
701
+ let b = a + 1;
702
+ while (b < scored.length && scored[b].score === scored[a].score) b++;
703
+ const tie = scored.slice(a, b);
704
+ if (tie.some(r => spelled.has(r))) {
705
+ tie.sort((x, y) => Number(spelled.has(y)) - Number(spelled.has(x)));
706
+ scored.splice(a, b - a, ...tie);
707
+ }
708
+ a = b;
709
+ }
593
710
  }
594
711
 
595
712
  // A family's root leads a part of its own family (its doc lists the part
@@ -602,10 +719,14 @@ export function rankLexical(query, options, catalog) {
602
719
  // asks for TabList before its Tab, and `code sample` for CodeBlock before
603
720
  // its Code, whatever their scores; a query holding
604
721
  // "item" keeps ListItem before List, and `breadcrumbitm` keeps
605
- // BreadcrumbItem first. The scores and this order stay as they are: the
722
+ // BreadcrumbItem first. A root whose hits are weaker than keyword strength
723
+ // leads only inside its part's run (weakRootsOf). The scores and this order
724
+ // stay as they are: the
606
725
  // order of matches moves the root directly before its part (rootLeadsOf).
607
726
  /** @type {Map<object, object>} */
608
727
  const rootLeads = new Map();
728
+ /** @type {Set<object>} */
729
+ const weakRoots = new Set();
609
730
  if (ranked.some(r => r.candidate._family)) {
610
731
  /** @type {Map<string, (typeof ranked)[number]>} */
611
732
  const byName = new Map();
@@ -615,14 +736,51 @@ export function rankLexical(query, options, catalog) {
615
736
  }
616
737
  const asked = nameWords(String(query));
617
738
  const typedJoined = String(query).trim().split(/\s+/).map(joined);
618
- /** @param {(typeof ranked)[number]} r */
619
- const misspelled = r =>
739
+ // A typed word that is the root's own name (`stack` for HStack's root
740
+ // Stack) asks for the root, not a misspelled part.
741
+ const misspelled = (
742
+ /** @type {(typeof ranked)[number]} */ r,
743
+ /** @type {string} */ family,
744
+ ) =>
620
745
  phraseWords(spellIdentifiers(String(r.candidate.name))).length >= 2 &&
621
- typedJoined.some(t => typoDistance(t, joined(r.candidate.name)) != null);
746
+ typedJoined.some(
747
+ t =>
748
+ t !== joined(family) &&
749
+ !pluralOf(t, joined(family)) &&
750
+ typoDistance(t, joined(r.candidate.name)) != null,
751
+ );
752
+ // Whether a root's own hits on the words its part answers have keyword
753
+ // strength (STRONG_TOKEN_SCORE: the whole name, the name's head word, or a
754
+ // keyword, also one edit away, since a misspelled
755
+ // name still names the root), not a word inside its name or a mention in
756
+ // its text. A root with weaker hits leads its part only inside the part's
757
+ // run (rootsFirst): `router` keeps a part whose keyword is `router` above
758
+ // a root whose description only mentions it.
759
+ /**
760
+ * @param {(typeof ranked)[number]} root
761
+ * @param {Set<string> | null} terms the words the part answered, or null
762
+ * for the whole query
763
+ */
764
+ const strong = (root, terms) => {
765
+ const scores = [...root.hits]
766
+ .filter(([t]) => !terms || terms.has(fold(t)))
767
+ .map(([, {hit}]) => hit?.score ?? 0);
768
+ return scores.length
769
+ ? scores.every(score => score >= STRONG_TOKEN_SCORE)
770
+ : root.key >= STRONG_TOKEN_SCORE;
771
+ };
622
772
  for (const r of ranked) {
623
773
  const family = r.candidate._family;
624
774
  const root = family && byName.get(`${r.result.domain}:${family}`);
625
- if (!root || root === r || typedSpan(r) || misspelled(r)) continue;
775
+ if (
776
+ !root ||
777
+ root === r ||
778
+ typedSpan(r) ||
779
+ misspelled(r, family) ||
780
+ spelledLed.has(r.result)
781
+ ) {
782
+ continue;
783
+ }
626
784
  const ofPart = answeredTerms(r.result.reason);
627
785
  const ofRoot = answeredTerms(root.result.reason);
628
786
  if (ofRoot && (!ofPart || [...ofPart].some(w => !ofRoot.has(w)))) {
@@ -634,6 +792,7 @@ export function rankLexical(query, options, catalog) {
634
792
  );
635
793
  if (own.some(w => asked.some(q => sameWord(q, w)))) continue;
636
794
  rootLeads.set(r.result, root.result);
795
+ if (!strong(root, ofPart)) weakRoots.add(r.result);
637
796
  }
638
797
  }
639
798
 
@@ -666,6 +825,7 @@ export function rankLexical(query, options, catalog) {
666
825
  }
667
826
  if (leads.size) namedLeadsOf.set(response, leads);
668
827
  if (rootLeads.size) rootLeadsOf.set(response, rootLeads);
828
+ if (weakRoots.size) weakRootsOf.set(response, weakRoots);
669
829
  if (catalog.searchedComponents) {
670
830
  searchedComponentsOf.set(
671
831
  response,
@@ -52,9 +52,11 @@ export function integrationTies(items: Item[]): Item[];
52
52
  * root's result
53
53
  * @param {Map<object, object>} [moved] filled with each part whose root
54
54
  * moved, mapped to that root
55
+ * @param {Set<object>} [weak] parts whose root leads them only inside their
56
+ * own run
55
57
  * @returns {Item[]}
56
58
  */
57
- export function rootsFirst(ranked: Item[], roots: Map<object, object>, moved?: Map<object, object>): Item[];
59
+ export function rootsFirst(ranked: Item[], roots: Map<object, object>, moved?: Map<object, object>, weak?: Set<object>): Item[];
58
60
  export function bandOf(score: number): number;
59
61
  export type EntryTable = import("./_entries.mjs").EntryTable;
60
62
  export type Item = {
@@ -6,7 +6,8 @@
6
6
  * reason. A match never moves past one of another score band (BANDS below)
7
7
  * or another kind, doc or not; between runs the lexical order holds. The one
8
8
  * exception is a family's root that the lexical ranker marks as leading its
9
- * part: it moves directly before the part. A band
9
+ * part with hits of keyword strength: it moves directly before the part. A
10
+ * band
10
11
  * can be wide: 55–99 holds keyword matches beside one-word description hits,
11
12
  * and a synonym name match can score under 55, so inside a band a weaker match
12
13
  * can lead a stronger one when the weights favor it. Inside such a
@@ -20,7 +21,8 @@
20
21
  * own name holds more query words leads (tieByOwnName). Last, a family's root
21
22
  * that the lexical ranker marks as leading a part of its own family
22
23
  * (rootLeadsOf) moves directly before the part when it sits below it
23
- * (rootsFirst), after the part's tie is ordered as one block.
24
+ * (rootsFirst), after the part's tie is ordered as one block; a root with
25
+ * weaker hits (weakRootsOf) moves so only inside the part's run.
24
26
  */
25
27
 
26
28
  import {entryOf} from './_entries.mjs';
@@ -31,6 +33,7 @@ import {
31
33
  namedLeadsOf,
32
34
  rootLeadsOf,
33
35
  searchedComponentsOf,
36
+ weakRootsOf,
34
37
  } from './_result.mjs';
35
38
 
36
39
  /** @typedef {import('./_entries.mjs').EntryTable} EntryTable */
@@ -94,6 +97,7 @@ export function orderMatches(table, order, lexical, query, limit, families) {
94
97
  };
95
98
  });
96
99
  const roots = rootLeadsOf.get(lexical);
100
+ const weak = weakRootsOf.get(lexical);
97
101
  // An entry the query names: by a name match, or by a name of two or more
98
102
  // words the lexical ranker put first (namedLeadsOf).
99
103
  const leads = namedLeadsOf.get(lexical);
@@ -137,11 +141,15 @@ export function orderMatches(table, order, lexical, query, limit, families) {
137
141
  // the roots move: a part's root, when the part comes first.
138
142
  const head = ranked[0];
139
143
  const headRoot = head && roots?.get(head.res);
140
- const lead = ranked.find(it => it.res === headRoot) ?? head;
144
+ const rootItem = ranked.find(it => it.res === headRoot);
145
+ const lead =
146
+ rootItem && !(weak?.has(head.res) && rootItem.band !== head.band)
147
+ ? rootItem
148
+ : head;
141
149
  ranked = tiesByFit(ranked, table, blockOf, lead);
142
150
  /** @type {Map<object, object>} */
143
151
  const moved = new Map();
144
- if (roots) ranked = rootsFirst(ranked, roots, moved);
152
+ if (roots) ranked = rootsFirst(ranked, roots, moved, weak);
145
153
  const shown = ranked.slice(0, limit);
146
154
  const response = {
147
155
  ...lexical,
@@ -358,15 +366,18 @@ function answered(it) {
358
366
  * root's result
359
367
  * @param {Map<object, object>} [moved] filled with each part whose root
360
368
  * moved, mapped to that root
369
+ * @param {Set<object>} [weak] parts whose root leads them only inside their
370
+ * own run
361
371
  * @returns {Item[]}
362
372
  */
363
- export function rootsFirst(ranked, roots, moved) {
373
+ export function rootsFirst(ranked, roots, moved, weak) {
364
374
  const out = [...ranked];
365
375
  for (let a = 0; a < out.length; a++) {
366
376
  const root = roots.get(out[a].res);
367
377
  if (!root) continue;
368
378
  const b = out.findIndex((it, n) => n > a && it.res === root);
369
379
  if (b < 0) continue;
380
+ if (weak?.has(out[a].res) && out[b].band !== out[a].band) continue;
370
381
  out.splice(a, 0, ...out.splice(b, 1));
371
382
  moved?.set(out[a + 1].res, root);
372
383
  }
@@ -128,4 +128,13 @@ export const rootLeadsOf: WeakMap<object, Map<object, object>>;
128
128
  * @type {WeakMap<object, Map<object, object>>}
129
129
  */
130
130
  export const movedRootsOf: WeakMap<object, Map<object, object>>;
131
+ /**
132
+ * The parts, by lexical response, whose root leads them on hits weaker than
133
+ * keyword strength (STRONG_TOKEN_SCORE; see rankLexical): such a root leads
134
+ * its part
135
+ * only inside the part's run. Module-private, so they never enter search's
136
+ * JSON.
137
+ * @type {WeakMap<object, Set<object>>}
138
+ */
139
+ export const weakRootsOf: WeakMap<object, Set<object>>;
131
140
  export type Candidate = import("./_lexical.mjs").Candidate;
@@ -168,6 +168,16 @@ export const rootLeadsOf = new WeakMap();
168
168
  */
169
169
  export const movedRootsOf = new WeakMap();
170
170
 
171
+ /**
172
+ * The parts, by lexical response, whose root leads them on hits weaker than
173
+ * keyword strength (STRONG_TOKEN_SCORE; see rankLexical): such a root leads
174
+ * its part
175
+ * only inside the part's run. Module-private, so they never enter search's
176
+ * JSON.
177
+ * @type {WeakMap<object, Set<object>>}
178
+ */
179
+ export const weakRootsOf = new WeakMap();
180
+
171
181
  /**
172
182
  * The query words a match answered: the terms its reason lists, folded, or
173
183
  * null when it answered the whole query (a name, keyword, or title hit).
@@ -209,6 +209,11 @@ export function scoreQuery(
209
209
  // Multi-word natural language: score each content token, counting only
210
210
  // strong hits, then reward coverage so candidates matching more terms win.
211
211
  let strongest = 0;
212
+ // The distinct query words a hit of keyword strength answers, or a word of
213
+ // the candidate's own name (see ownName below). A word said twice counts
214
+ // once.
215
+ /** @type {Set<string>} */
216
+ const strongWords = new Set();
212
217
  // Words the candidate answers with its own text: not only through a
213
218
  // component a template uses (see STRONG_TOKEN_SCORE). A word of its own
214
219
  // name, display name or title, or the start of one, is its own answer,
@@ -256,10 +261,16 @@ export function scoreQuery(
256
261
  }
257
262
  if (h && h.score >= MIN_TOKEN_SCORE) {
258
263
  if (h.score > strongest) strongest = h.score;
264
+ /** @type {boolean | undefined} */
265
+ let inOwnName;
266
+ const own = () => (inOwnName ??= ownName(tok));
267
+ if (h.score >= STRONG_TOKEN_SCORE || (ownEvidence && own())) {
268
+ strongWords.add(joined(tok));
269
+ }
259
270
  if (
260
271
  !('used' in h && h.used) ||
261
272
  (h.own ?? 0) >= MIN_TOKEN_SCORE ||
262
- ownName(tok)
273
+ own()
263
274
  ) {
264
275
  ownMatched++;
265
276
  }
@@ -303,6 +314,7 @@ export function scoreQuery(
303
314
  for (const tok of tokens) {
304
315
  if (!hitTerms.includes(tok) && inTitle(tok)) {
305
316
  if (STRONG_TOKEN_SCORE > strongest) strongest = STRONG_TOKEN_SCORE;
317
+ strongWords.add(joined(tok));
306
318
  matched++;
307
319
  ownMatched++;
308
320
  hitTerms.push(tok);
@@ -321,7 +333,12 @@ export function scoreQuery(
321
333
  // both; a candidate that has both comes first, ordered among its peers by
322
334
  // how strong its matches are. It needs one keyword-strength hit:
323
335
  // every word mentioned in prose, or rendered by a page, is breadth, and
324
- // stays on the token sum below an exact hit on one word.
336
+ // stays on the token sum below an exact hit on one word. In search's
337
+ // reading (`ownEvidence`), an entry that is not a doc needs two strong
338
+ // words: a hit of keyword strength, or a word of its own name, display
339
+ // name or title, or the start of one. One strong word and a mention of the others is a match on
340
+ // that word, not on the ask. A doc answers in prose, so it keeps the bar
341
+ // of one.
325
342
  //
326
343
  // The TOTAL quality of matches orders candidates within this tier, not
327
344
  // just the strongest single hit. A doc matching both words by keyword
@@ -331,7 +348,8 @@ export function scoreQuery(
331
348
  if (
332
349
  matched === tokens.length &&
333
350
  ownMatched === tokens.length &&
334
- strongest >= STRONG_TOKEN_SCORE
351
+ strongest >= STRONG_TOKEN_SCORE &&
352
+ (!ownEvidence || candidate.domain === 'doc' || strongWords.size >= 2)
335
353
  ) {
336
354
  return {
337
355
  score:
@@ -170,3 +170,11 @@ export type CopyPlan = {
170
170
  */
171
171
  dependencies: Record<string, string>;
172
172
  };
173
+ /**
174
+ * Export origins by module, as {@link moduleExportOrigins} memoizes them:
175
+ * value and type reads apart.
176
+ */
177
+ export type ExportMemos = {
178
+ value: Map<string, any>;
179
+ type: Map<string, any>;
180
+ };
@@ -29,6 +29,7 @@ import {
29
29
  isRecord,
30
30
  subpathDeclaration,
31
31
  } from '../../foundation/integrations/exports-subpaths.mjs';
32
+ import {reusedWhileUnchangedSync} from '../../foundation/fs/read-record.mjs';
32
33
 
33
34
  /** The extensions an extensionless import may name, in resolution order. */
34
35
  const CODE_FILE = /\.[cm]?[jt]sx?$/;
@@ -376,6 +377,53 @@ function publicSurfaceOf(packageDir, srcRoot, originsOf) {
376
377
  return {byOrigin, byFile, exportsField};
377
378
  }
378
379
 
380
+ /**
381
+ * Export origins by module, as {@link moduleExportOrigins} memoizes them:
382
+ * value and type reads apart.
383
+ * @typedef {{value: Map<string, any>, type: Map<string, any>}} ExportMemos
384
+ */
385
+
386
+ /**
387
+ * The read of each package's public surface, by package and source root,
388
+ * with the export origins that read found. Reading one parses every module
389
+ * the package exports, more than the parsed-module cache keeps, so without
390
+ * this each copy from the same package in one process parses them all again.
391
+ * @type {Map<string, () => {surface: PublicSurface, memos: ExportMemos}>}
392
+ */
393
+ const surfaceReads = new Map();
394
+
395
+ /**
396
+ * {@link publicSurfaceOf}, reused while every file and folder it read is
397
+ * unchanged, with the export origins it found. Each read caches export
398
+ * origins for that read only, so a read after a change sees the package as
399
+ * it is then.
400
+ * @param {string} packageDir
401
+ * @param {string} srcRoot
402
+ * @returns {{surface: PublicSurface, memos: ExportMemos}}
403
+ */
404
+ function keptPublicSurfaceOf(packageDir, srcRoot) {
405
+ const key = `${packageDir}\0${srcRoot}`;
406
+ let read = surfaceReads.get(key);
407
+ if (read == null) {
408
+ read = reusedWhileUnchangedSync(
409
+ () => {
410
+ /** @type {ExportMemos} */
411
+ const memos = {value: new Map(), type: new Map()};
412
+ const surface = publicSurfaceOf(packageDir, srcRoot, (file, kind) =>
413
+ moduleExportOrigins(file, {
414
+ types: kind === 'type',
415
+ memo: memos[kind],
416
+ }),
417
+ );
418
+ return {surface, memos};
419
+ },
420
+ {exact: true},
421
+ );
422
+ surfaceReads.set(key, read);
423
+ }
424
+ return read();
425
+ }
426
+
379
427
  /**
380
428
  * A specifier that is either fixed (a public subpath) or computed from where
381
429
  * two copied files land.
@@ -421,8 +469,9 @@ export function planCopy({
421
469
  ownerPackage,
422
470
  entries,
423
471
  }) {
424
- // Every read is cached for this copy only, so a later copy sees the
425
- // package as it is then.
472
+ // Export reads are cached for this copy only, so a later copy sees the
473
+ // package as it is then. The package surface is kept across copies while
474
+ // what it read is unchanged.
426
475
  const exportMemos = {value: new Map(), type: new Map()};
427
476
  /** @type {OriginsOf} */
428
477
  const originsOf = (file, kind) =>
@@ -472,7 +521,16 @@ export function planCopy({
472
521
  * @param {{packageDir: string, srcRoot: string, ownerPackage: string}} pkg
473
522
  */
474
523
  function makeContext({packageDir, srcRoot, ownerPackage}) {
475
- const surface = publicSurfaceOf(packageDir, srcRoot, originsOf);
524
+ const kept = keptPublicSurfaceOf(packageDir, srcRoot);
525
+ const {surface} = kept;
526
+ // The surface read's origins hold while the surface is kept. Copy them in
527
+ // so this copy reads no exported module again; what this copy adds stays
528
+ // in its own memo, since the surface's change check does not cover it.
529
+ for (const kind of /** @type {const} */ (['value', 'type'])) {
530
+ for (const [file, origins] of kept.memos[kind]) {
531
+ if (!exportMemos[kind].has(file)) exportMemos[kind].set(file, origins);
532
+ }
533
+ }
476
534
  /** @param {string} file */
477
535
  const inSource = file => file.startsWith(srcRoot + path.sep);
478
536
  /**
@@ -143,9 +143,11 @@ export function templateCopy(
143
143
  `Invalid template target path "${given}": it is outside the project root (${path.resolve(cwd)}). ` +
144
144
  (scratchPath
145
145
  ? `A scratch copy in the system temp folder takes its absolute path, ${scratchPath}.`
146
- : scratchFolder
147
- ? `The template is written only inside the project, or as a scratch copy in the system temp folder (${scratchFolder}). Give a path inside one, or print the source.`
148
- : 'The template is written only inside the project. Give a path inside it, or print the source.'),
146
+ : there
147
+ ? `The template is written only inside the folder the command runs in${scratchFolder ? `, or as a scratch copy in the system temp folder (${scratchFolder})` : ''}. Give a path inside the project, run the command from the destination's folder, or print the source.`
148
+ : scratchFolder
149
+ ? `The template is written only inside the project, or as a scratch copy in the system temp folder (${scratchFolder}). Give a path inside one, or print the source.`
150
+ : 'The template is written only inside the project. Give a path inside it, or print the source.'),
149
151
  [
150
152
  {
151
153
  name: `${command} ${quoteCommandArgument(folder)}`,
@@ -1383,6 +1383,49 @@ async function withThemeAppLock(cwd, fn) {
1383
1383
  }
1384
1384
  }
1385
1385
 
1386
+ /**
1387
+ * The ways forward from `theme add` of a slug no theme has: a near name (a
1388
+ * typo) leads, as the command meant; then, unless a package was named, the
1389
+ * doc on where a theme you wrote must live; then the other themes, nearest
1390
+ * first.
1391
+ * @param {string} slug
1392
+ * @param {Array<any>} available
1393
+ * @param {string} cwd
1394
+ * @param {string | undefined} pkg
1395
+ */
1396
+ function unknownThemeSuggestions(slug, available, cwd, pkg) {
1397
+ const themes = themeCommandsFor('theme add', slug, available, cwd).map(
1398
+ ({theme, name}) => ({
1399
+ name,
1400
+ reason:
1401
+ theme.source === 'bundled'
1402
+ ? 'bundled theme'
1403
+ : theme.source === 'local'
1404
+ ? 'local theme'
1405
+ : `provided by ${theme.package}`,
1406
+ distance: levenshteinDistance(
1407
+ String(slug).toLowerCase(),
1408
+ theme.slug.toLowerCase(),
1409
+ ),
1410
+ }),
1411
+ );
1412
+ const near = Math.min(3, Math.max(1, Math.floor(String(slug).length / 3)));
1413
+ const lead = themes.filter(theme => theme.distance <= near);
1414
+ const rest = themes.filter(theme => theme.distance > near);
1415
+ const docs = pkg
1416
+ ? []
1417
+ : [
1418
+ {
1419
+ name: formatCliCommand(
1420
+ 'docs author-a-theme creating-a-custom-theme',
1421
+ cwd,
1422
+ ),
1423
+ reason: `how a theme you wrote lives in ${LOCAL_THEME_ROOT}/ so theme add finds it`,
1424
+ },
1425
+ ];
1426
+ return [...lead, ...docs, ...rest].map(({name, reason}) => ({name, reason}));
1427
+ }
1428
+
1386
1429
  /**
1387
1430
  * Add one available built theme to the app record.
1388
1431
  * @param {string} slug
@@ -1405,19 +1448,12 @@ async function addThemeToAppLocked(slug, cwd, options) {
1405
1448
  const match = await findTheme(slug, {cwd, package: options.package});
1406
1449
  if (!match) {
1407
1450
  const available = await listAvailableThemes(cwd);
1451
+ // A theme the person wrote and built elsewhere is no theme `theme add`
1452
+ // finds by name: the message says where one must live to be added, and
1453
+ // how a built theme is used without it.
1408
1454
  throw new AstryxError(
1409
- `Unknown theme "${slug}"${options.package ? ` in package "${options.package}"` : ''}.`,
1410
- themeCommandsFor('theme add', slug, available, cwd).map(
1411
- ({theme, name}) => ({
1412
- name,
1413
- reason:
1414
- theme.source === 'bundled'
1415
- ? 'bundled theme'
1416
- : theme.source === 'local'
1417
- ? 'local theme'
1418
- : `provided by ${theme.package}`,
1419
- }),
1420
- ),
1455
+ `Unknown theme "${slug}"${options.package ? ` in package "${options.package}"` : ''}.${options.package ? '' : ` A theme you wrote is added by name from ${LOCAL_THEME_ROOT}/<slug>/, where a theme source sits beside a same-stem .doc.mjs descriptor; a theme you built elsewhere needs no add: import its built module and stylesheet in your app, as theme build prints with --detail full.`}`,
1456
+ unknownThemeSuggestions(slug, available, cwd, options.package),
1421
1457
  ERROR_CODES.ERR_UNKNOWN_THEME,
1422
1458
  );
1423
1459
  }