@astryxdesign/cli 0.7.16 → 0.7.17-canary.gb36275e

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 (239) hide show
  1. package/README.md +13 -23
  2. package/api/build/_adapter.d.mts +5 -0
  3. package/api/build/_adapter.mjs +49 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +2 -1
  7. package/api/build/kit/rank.mjs +59 -12
  8. package/api/build/kit/weights.d.mts +16 -3
  9. package/api/build/kit/weights.json +1 -1
  10. package/api/build/kit/weights.mjs +238 -31
  11. package/api/build/kit/word-model.d.mts +23 -0
  12. package/api/build/kit/word-model.mjs +46 -0
  13. package/api/build/kit/words.d.mts +42 -0
  14. package/api/build/kit/words.mjs +82 -1
  15. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  16. package/api/component/list/list.d.mts +1 -1
  17. package/api/component/list/list.mjs +46 -5
  18. package/api/discover/_adapter.d.mts +1 -1
  19. package/api/docs/_adapter.d.mts +26 -2
  20. package/api/docs/_adapter.mjs +217 -5
  21. package/api/docs/docs.d.mts +3 -0
  22. package/api/docs/docs.doc.mjs +7 -1
  23. package/api/docs/docs.mjs +12 -0
  24. package/api/docs/docs.type.d.mts +5 -0
  25. package/api/docs/docs.type.mjs +2 -0
  26. package/api/docs/node/node.mjs +1 -1
  27. package/api/doctor/_adapter.d.mts +27 -5
  28. package/api/doctor/_adapter.mjs +77 -6
  29. package/api/doctor/built-checks.mjs +38 -13
  30. package/api/doctor/doctor.d.mts +4 -3
  31. package/api/doctor/doctor.mjs +14 -7
  32. package/api/doctor/theme-checks.mjs +121 -17
  33. package/api/render/_adapter.mjs +531 -192
  34. package/api/render/render.doc.mjs +11 -3
  35. package/api/render/render.type.d.mts +30 -0
  36. package/api/render/render.type.mjs +19 -0
  37. package/api/search/ORDERING.md +1 -1
  38. package/api/search/_candidate-score.mjs +51 -32
  39. package/api/search/_fit-order.mjs +3 -3
  40. package/api/search/_result.d.mts +5 -5
  41. package/api/search/_score.d.mts +6 -1
  42. package/api/search/_score.mjs +15 -3
  43. package/api/search/search.d.mts +1 -1
  44. package/api/theme/_adapter.mjs +10 -0
  45. package/api/theme/build/build.d.mts +47 -0
  46. package/api/theme/build/build.mjs +147 -25
  47. package/api/theme/theme.type.d.mts +10 -0
  48. package/api/theme/theme.type.mjs +7 -1
  49. package/api/theme-edit/_adapter.d.mts +48 -0
  50. package/api/theme-edit/_adapter.mjs +675 -42
  51. package/api/theme-edit/_check.d.mts +28 -22
  52. package/api/theme-edit/_check.mjs +1481 -252
  53. package/api/theme-edit/_color.d.mts +9 -0
  54. package/api/theme-edit/_color.mjs +41 -1
  55. package/api/theme-edit/_compiler.mjs +9 -0
  56. package/api/theme-edit/_context.mjs +60 -3
  57. package/api/theme-edit/_css.mjs +21 -1
  58. package/api/theme-edit/_edit.d.mts +22 -0
  59. package/api/theme-edit/_edit.mjs +1196 -88
  60. package/api/theme-edit/_how-commands.d.mts +57 -0
  61. package/api/theme-edit/_how-commands.mjs +536 -1
  62. package/api/theme-edit/_how-question.d.mts +65 -0
  63. package/api/theme-edit/_how-question.mjs +4401 -225
  64. package/api/theme-edit/_how.mjs +104 -4
  65. package/api/theme-edit/_marks.d.mts +31 -5
  66. package/api/theme-edit/_marks.mjs +57 -5
  67. package/api/theme-edit/_normal.d.mts +153 -0
  68. package/api/theme-edit/_normal.mjs +661 -0
  69. package/api/theme-edit/_palette.mjs +10 -4
  70. package/api/theme-edit/_parts.d.mts +8 -0
  71. package/api/theme-edit/_parts.mjs +103 -2
  72. package/api/theme-edit/_preview-app.d.mts +7 -1
  73. package/api/theme-edit/_preview-app.mjs +205 -17
  74. package/api/theme-edit/_preview.d.mts +64 -8
  75. package/api/theme-edit/_preview.mjs +447 -89
  76. package/api/theme-edit/_settings.d.mts +176 -5
  77. package/api/theme-edit/_settings.mjs +1936 -128
  78. package/api/theme-edit/_tables.d.mts +6 -0
  79. package/api/theme-edit/_tables.mjs +32 -1
  80. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  81. package/api/theme-edit/theme-edit.type.mjs +4 -1
  82. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  83. package/assets/codemods/run-codemod.mjs +73 -6
  84. package/assets/codemods/transforms/next/index.mjs +11 -1
  85. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  86. package/assets/docs/author-a-theme.doc.mjs +1 -0
  87. package/assets/docs/theme.doc.dense.mjs +2 -2
  88. package/assets/docs/theme.doc.mjs +1 -1
  89. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  90. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  91. package/assets/docs/tree/render-pages.doc.mjs +43 -2
  92. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  93. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  94. package/assets/docs/use-a-theme.doc.mjs +1 -1
  95. package/assets/docs.generated.json +2 -2
  96. package/assets/self-audit.generated.json +1 -1
  97. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  98. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  99. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  100. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  101. package/assets/templates/components.generated.json +1 -1
  102. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  103. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  104. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  105. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  106. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  107. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  108. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  109. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  110. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  111. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  112. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  113. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  114. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  115. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  116. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  117. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  118. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  119. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  120. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  121. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  122. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  123. package/assets/templates/pages/ide/page.tsx +24 -2
  124. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  125. package/assets/templates/pages/library/template.doc.mjs +4 -1
  126. package/assets/templates/pages/login/template.doc.mjs +2 -1
  127. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  128. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  129. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  130. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  131. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  132. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  133. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  134. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  135. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  136. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  137. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  138. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  139. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  140. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  141. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  142. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  143. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  144. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  145. package/authoring/debug/parse.d.mts +3 -3
  146. package/authoring/doctypes/_schema.d.mts +3 -3
  147. package/authoring/doctypes/command/command.doc.mjs +1 -1
  148. package/authoring/doctypes/template/template.doc.mjs +1 -1
  149. package/authoring/doctypes/template/type.ts +9 -0
  150. package/clients/cli/bin/astryx.mjs +6 -9
  151. package/clients/cli/build-id.generated.json +1 -1
  152. package/clients/cli/commands/component.doc.mjs +1 -1
  153. package/clients/cli/commands/component.mjs +20 -2
  154. package/clients/cli/commands/docs.doc.mjs +7 -1
  155. package/clients/cli/commands/docs.mjs +3 -1
  156. package/clients/cli/commands/doctor.mjs +22 -14
  157. package/clients/cli/commands/experimental/render.mjs +32 -1
  158. package/clients/cli/commands/experimental/theme.mjs +65 -14
  159. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  160. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  161. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  162. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  163. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  164. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  165. package/clients/cli/commands/search.doc.mjs +2 -1
  166. package/clients/cli/commands/search.mjs +6 -1
  167. package/clients/cli/commands/template.mjs +4 -2
  168. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  169. package/clients/cli/commands/theme.doc.mjs +1 -1
  170. package/clients/cli/commands/theme.mjs +153 -5
  171. package/clients/cli/commands/upgrade.mjs +42 -7
  172. package/clients/cli/index.mjs +1 -1
  173. package/clients/cli/lib/component-format.mjs +205 -98
  174. package/clients/cli/lib/hook-format.mjs +9 -19
  175. package/clients/cli/manifest.generated.json +1 -1
  176. package/foundation/agent-docs/agent-docs.mjs +1 -1
  177. package/foundation/config/theme-state.d.mts +13 -1
  178. package/foundation/config/theme-state.mjs +47 -7
  179. package/foundation/discovery/component-discovery.d.mts +11 -0
  180. package/foundation/discovery/component-discovery.mjs +27 -2
  181. package/foundation/discovery/component-replacement.mjs +130 -1
  182. package/foundation/discovery/entry-name-files.d.mts +43 -0
  183. package/foundation/discovery/entry-name-files.mjs +264 -0
  184. package/foundation/discovery/hook-discovery.d.mts +8 -2
  185. package/foundation/discovery/hook-discovery.mjs +20 -7
  186. package/foundation/discovery/package-exports.d.mts +10 -0
  187. package/foundation/discovery/package-exports.mjs +56 -3
  188. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  189. package/foundation/discovery/runner-allowlist.mjs +2 -0
  190. package/foundation/discovery/template-adapter.d.mts +52 -0
  191. package/foundation/discovery/template-adapter.mjs +173 -10
  192. package/foundation/discovery/theme-imports.d.mts +14 -0
  193. package/foundation/discovery/theme-imports.mjs +43 -1
  194. package/foundation/doc-compiler/import.mjs +7 -1
  195. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  196. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  197. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  198. package/foundation/fs/cache-eviction.d.mts +21 -0
  199. package/foundation/fs/cache-eviction.mjs +73 -0
  200. package/foundation/fs/gather-cache.d.mts +25 -4
  201. package/foundation/fs/gather-cache.mjs +163 -53
  202. package/foundation/fs/jiti-cache.d.mts +19 -1
  203. package/foundation/fs/jiti-cache.mjs +130 -6
  204. package/foundation/fs/kept-tree.d.mts +60 -0
  205. package/foundation/fs/kept-tree.mjs +154 -0
  206. package/foundation/fs/module-loader.d.mts +18 -2
  207. package/foundation/fs/module-loader.mjs +92 -20
  208. package/foundation/identity/provider-identity.d.mts +6 -0
  209. package/foundation/identity/provider-identity.mjs +10 -1
  210. package/foundation/render/embedded-imports.d.mts +5 -4
  211. package/foundation/render/embedded-imports.mjs +7 -16
  212. package/foundation/render/file-header.d.mts +66 -0
  213. package/foundation/render/file-header.mjs +118 -0
  214. package/foundation/render/host-answer.d.mts +18 -0
  215. package/foundation/render/host-answer.mjs +46 -0
  216. package/foundation/render/host-exit.d.mts +1 -0
  217. package/foundation/render/host-exit.mjs +6 -1
  218. package/foundation/render/html-reader.d.mts +55 -2
  219. package/foundation/render/html-reader.mjs +145 -26
  220. package/foundation/render/markup-edits.d.mts +57 -0
  221. package/foundation/render/markup-edits.mjs +182 -0
  222. package/foundation/render/page-host.mjs +29 -12
  223. package/foundation/render/page-worker.mjs +83 -13
  224. package/foundation/render/render-page.d.mts +34 -2
  225. package/foundation/render/render-page.mjs +210 -29
  226. package/foundation/render/source-block.d.mts +73 -6
  227. package/foundation/render/source-block.mjs +170 -19
  228. package/foundation/render/ts-paths.d.mts +53 -6
  229. package/foundation/render/ts-paths.mjs +286 -41
  230. package/foundation/response/error-codes.d.mts +3 -1
  231. package/foundation/response/error-codes.d.ts +1 -0
  232. package/foundation/response/error-codes.doc.mjs +12 -1
  233. package/foundation/response/error-codes.mjs +10 -0
  234. package/foundation/text/string-utils.d.mts +3 -2
  235. package/foundation/text/string-utils.mjs +16 -3
  236. package/foundation/text/suggest-order.d.mts +9 -0
  237. package/foundation/text/suggest-order.mjs +13 -0
  238. package/host/index.mjs +8 -6
  239. package/package.json +6 -6
@@ -1,9 +1,11 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Word weights for `build`'s START (spec:AST-048): a checked-in table of
5
- * per-template word weights, blended with the page ranker's own scores, picks
6
- * the template an idea starts from.
4
+ * @file Word weights for `build`'s START (spec:AST-048): checked-in tables of
5
+ * per-template word weights, blended with the page ranker's own scores, pick
6
+ * the template an idea starts from. The call model (the file's top-level
7
+ * tables and blend) decides page or app shell; an optional pick model
8
+ * (`pick`) chooses which page once the call model calls a page.
7
9
  *
8
10
  * @input An idea, the ranker's output for it (`rankPages`, `pickStart`), the
9
11
  * project's ready page templates, and the weights (`weights.json` beside this
@@ -20,6 +22,8 @@
20
22
  */
21
23
 
22
24
  import {STOPWORDS} from '../../search/search.mjs';
25
+ import {keywordUnits, keywordWordsFor} from './words.mjs';
26
+ import {isWordModel} from './word-model.mjs';
23
27
 
24
28
  /** The app shell, as one candidate. */
25
29
  export const SHELL = 'SHELL';
@@ -160,8 +164,34 @@ export function weightWords(idea) {
160
164
  * @property {WeightTable[]} tables
161
165
  * @property {number[]} blend three numbers per member (the tables, in order,
162
166
  * with the ranker second), then one for `SHELL`
167
+ * @property {{tables: WeightTable[], blend: number[]}} [pick] the pick
168
+ * model: its own tables and blend numbers, used only to choose which page
169
+ * starts once the call model (the top-level tables and blend) has called a
170
+ * page. Without it, one model does both.
163
171
  */
164
172
 
173
+ /**
174
+ * Whether the weights file carries a well-formed pick model. A malformed
175
+ * `pick` block is ignored, so one model then does both decisions.
176
+ * @param {WeightsFile} weights
177
+ * @returns {boolean}
178
+ */
179
+ const hasPickModel = weights =>
180
+ isWordModel(weights.pick, weights.candidates.length);
181
+
182
+ /**
183
+ * The pick model of a weights file: its `pick` tables and blend when present,
184
+ * else the file's own.
185
+ * @param {WeightsFile} weights
186
+ * @returns {WeightsFile}
187
+ */
188
+ const pickModel = weights => {
189
+ const pick = weights.pick;
190
+ return pick && hasPickModel(weights)
191
+ ? {...weights, tables: pick.tables, blend: pick.blend}
192
+ : weights;
193
+ };
194
+
165
195
  /**
166
196
  * A table's score for every candidate.
167
197
  * @param {WeightTable} table
@@ -233,32 +263,68 @@ function memberFeatures(v) {
233
263
  * @property {string} [displayName]
234
264
  * @property {string} [category]
235
265
  * @property {string[]} [keywords]
266
+ * @property {string} [description]
267
+ * @property {string[]} [components]
236
268
  */
237
269
 
238
270
  /**
239
- * How many of the idea's stemmed words a template's own descriptor names: its
240
- * display name, its category, and its keywords, less search's stopwords.
271
+ * The words of a descriptor text as this file reads an idea: stemmed, less
272
+ * search's stopwords. Search's stopwords are no evidence: "to" in a "to-do
273
+ * list" keyword must not answer the "to" of "rows to track orders".
274
+ * @param {string} text
275
+ * @returns {string[]}
276
+ */
277
+ const contentWords = text =>
278
+ weightWords(text)
279
+ .filter(w => !STOPWORDS.has(w))
280
+ .map(stem);
281
+
282
+ /**
283
+ * The words a template's descriptor gives an idea: every word of `texts`, and
284
+ * the words its keywords give the idea (`keywordWordsFor`): a phrase keyword
285
+ * counts all of its words when the idea names the whole phrase, and none of
286
+ * them otherwise.
287
+ * @param {string[]} texts
288
+ * @param {readonly string[]} keywords
289
+ * @param {string[]} order the idea's words, in order (`contentWords`)
290
+ * @returns {Set<string>}
291
+ */
292
+ const descriptorWordsFor = (texts, keywords, order) =>
293
+ new Set([
294
+ ...contentWords(texts.join(' ')),
295
+ ...keywordWordsFor(keywordUnits(keywords, contentWords), order),
296
+ ]);
297
+
298
+ /**
299
+ * How many of the idea's words a template's own descriptor names: its display
300
+ * name, its category, and its keywords.
241
301
  * @param {string} name
242
302
  * @param {DescribedTemplate[]} catalog
243
- * @param {Set<string>} words the idea's stemmed words, less search's stopwords
303
+ * @param {string[]} order the idea's words, in order (`contentWords`)
244
304
  */
245
- function ownWords(name, catalog, words) {
305
+ function ownWords(name, catalog, order) {
246
306
  const t = catalog.find(c => c.name === name);
247
307
  if (!t) return 0;
248
- // Search's stopwords are no evidence: "to" in a "to-do list" keyword must
249
- // not answer the "to" of "rows to track orders".
250
- const own = new Set(
251
- weightWords(
252
- [t.displayName ?? '', t.category ?? '', ...(t.keywords ?? [])].join(' '),
253
- )
254
- .filter(w => !STOPWORDS.has(w))
255
- .map(stem),
308
+ const own = descriptorWordsFor(
309
+ [t.displayName ?? '', t.category ?? ''],
310
+ t.keywords ?? [],
311
+ order,
256
312
  );
257
313
  let n = 0;
258
- for (const w of words) if (own.has(w)) n++;
314
+ for (const w of new Set(order)) if (own.has(w)) n++;
259
315
  return n;
260
316
  }
261
317
 
318
+ /**
319
+ * A template's family: the part of its category before ` - `.
320
+ * @param {string} name
321
+ * @param {DescribedTemplate[]} catalog
322
+ */
323
+ const familyOf = (name, catalog) =>
324
+ String(catalog.find(c => c.name === name)?.category ?? '')
325
+ .split(' - ')[0]
326
+ .trim();
327
+
262
328
  /** How many fewer own words a template whose family the idea names first may
263
329
  * name than the listed template it competes with, and still start. */
264
330
  const FAMILY_SLACK = 2;
@@ -330,6 +396,132 @@ function blend(idea, ranked, pick, catalog, weights) {
330
396
  return {cands, scores, position};
331
397
  }
332
398
 
399
+ /**
400
+ * The most typical of the ready templates the ranker ties with `name` in its
401
+ * family (same score, same id length): the one whose descriptor's words are
402
+ * shared by the most of its family's templates, on average. `name` keeps its
403
+ * place on an equal value. Reads only the templates' descriptors.
404
+ * @param {string} name
405
+ * @param {import('./rank.mjs').RankedPage[]} ranked
406
+ * @param {string[]} cands
407
+ * @returns {string}
408
+ */
409
+ function typicalOfTie(name, ranked, cands) {
410
+ const self = ranked.find(r => r.name === name);
411
+ if (!self || self.family === SHELL_FAMILY || !self.family) return name;
412
+ const length = (/** @type {string} */ n) => n.split('-').length;
413
+ let chosen = self;
414
+ for (const r of ranked) {
415
+ if (
416
+ r.score === self.score &&
417
+ r.family === self.family &&
418
+ length(r.name) === length(self.name) &&
419
+ cands.includes(r.name) &&
420
+ r.typical > chosen.typical
421
+ )
422
+ chosen = r;
423
+ }
424
+ return chosen.name;
425
+ }
426
+
427
+ /**
428
+ * The words a template's whole descriptor gives an idea
429
+ * (`descriptorWordsFor`): its display name, category, keywords, description,
430
+ * and the names of the components its page composes.
431
+ * @param {DescribedTemplate} t
432
+ * @param {string[]} order the idea's words, in order (`contentWords`)
433
+ * @returns {Set<string>}
434
+ */
435
+ function descriptorWords(t, order) {
436
+ const components = (t.components ?? []).map(c =>
437
+ c.replace(/([a-z0-9])([A-Z])/g, '$1 $2'),
438
+ );
439
+ return descriptorWordsFor(
440
+ [t.displayName ?? '', t.category ?? '', t.description ?? '', ...components],
441
+ t.keywords ?? [],
442
+ order,
443
+ );
444
+ }
445
+
446
+ /**
447
+ * Settles an exact tie in the ranker by a fuller reading of each tied
448
+ * template's own descriptor. Words every tied template names cannot choose
449
+ * between them, so they are left out; each other word of the idea that a
450
+ * template's descriptor names adds its rarity within the family. The highest
451
+ * total starts. An equal total goes to the most typical of the family
452
+ * (`typicalOfTie`), then to `name`. Reads only the templates' descriptors.
453
+ * @param {string} name
454
+ * @param {string} idea
455
+ * @param {import('./rank.mjs').RankedPage[]} ranked
456
+ * @param {string[]} cands
457
+ * @param {DescribedTemplate[]} catalog
458
+ * @returns {string}
459
+ */
460
+ function fullerOfTie(name, idea, ranked, cands, catalog) {
461
+ const self = ranked.find(r => r.name === name);
462
+ if (!self || self.family === SHELL_FAMILY || !self.family) return name;
463
+ const length = (/** @type {string} */ n) => n.split('-').length;
464
+ const tied = ranked.filter(
465
+ r =>
466
+ r.score === self.score &&
467
+ r.family === self.family &&
468
+ length(r.name) === length(self.name) &&
469
+ cands.includes(r.name),
470
+ );
471
+ if (tied.length < 2) return name;
472
+ const family = catalog.filter(t => familyOf(t.name, catalog) === self.family);
473
+ const order = contentWords(idea);
474
+ const words = new Map(family.map(t => [t.name, descriptorWords(t, order)]));
475
+ const df = (/** @type {string} */ w) =>
476
+ family.filter(t => words.get(t.name)?.has(w)).length;
477
+ const said = new Set(order);
478
+ const own = tied.map(r => words.get(r.name) ?? new Set());
479
+ const n = family.length;
480
+ const score = tied.map((_, i) => {
481
+ let s = 0;
482
+ for (const w of said) {
483
+ if (!own[i].has(w) || own.every(o => o.has(w))) continue;
484
+ const d = df(w);
485
+ s += Math.log(1 + (n - d + 0.5) / (d + 0.5));
486
+ }
487
+ return s;
488
+ });
489
+ const top = Math.max(...score);
490
+ if (top === 0) return typicalOfTie(name, ranked, cands);
491
+ const leaders = tied.filter((_, i) => score[i] >= top - 1e-9);
492
+ if (leaders.length === 1) return leaders[0].name;
493
+ const lead = leaders.some(r => r.name === name) ? self : leaders[0];
494
+ return typicalOfTie(
495
+ lead.name,
496
+ ranked,
497
+ leaders.map(r => r.name),
498
+ );
499
+ }
500
+
501
+ /**
502
+ * The pick model's best ready, non-shell template, or null when it has none.
503
+ * @param {string} idea
504
+ * @param {import('./rank.mjs').RankedPage[]} ranked
505
+ * @param {import('./rank.mjs').RankedPage | null} pick
506
+ * @param {DescribedTemplate[]} catalog
507
+ * @param {WeightsFile} weights
508
+ * @returns {string | null}
509
+ */
510
+ function bestPage(idea, ranked, pick, catalog, weights) {
511
+ const {cands, scores} = blend(
512
+ idea,
513
+ ranked,
514
+ pick,
515
+ catalog,
516
+ pickModel(weights),
517
+ );
518
+ let at = -1;
519
+ for (let c = 0; c < cands.length; c++) {
520
+ if (cands[c] !== SHELL && (at < 0 || scores[c] > scores[at])) at = c;
521
+ }
522
+ return at < 0 ? null : cands[at];
523
+ }
524
+
333
525
  /**
334
526
  * Every ready, non-shell template in the blend's own order, best first: the
335
527
  * order the page start is chosen from, so the alternatives build names beside
@@ -343,7 +535,13 @@ function blend(idea, ranked, pick, catalog, weights) {
343
535
  */
344
536
  export function blendOrder(idea, ranked, pick, catalog, weights) {
345
537
  if (!weights) return null;
346
- const {cands, scores} = blend(idea, ranked, pick, catalog, weights);
538
+ const {cands, scores} = blend(
539
+ idea,
540
+ ranked,
541
+ pick,
542
+ catalog,
543
+ pickModel(weights),
544
+ );
347
545
  return cands
348
546
  .map((c, i) => ({c, s: scores[i], i}))
349
547
  .filter(x => x.c !== SHELL)
@@ -397,22 +595,28 @@ export function weighStart(
397
595
  if (!listed) return kept;
398
596
  // The idea's own words, less search's stopwords: "basically" must not
399
597
  // answer the "Basic" of a category.
400
- const content = weightWords(idea).filter(w => !STOPWORDS.has(w));
401
- const said = new Set(content.map(stem));
402
- const mine = ownWords(kept, catalog, said);
403
- const theirs = ownWords(listed, catalog, said);
404
- if (mine >= theirs) return kept;
598
+ const order = contentWords(idea);
599
+ const mine = ownWords(kept, catalog, order);
600
+ const theirs = ownWords(listed, catalog, order);
405
601
  // An idea that names the template's family before the listed one's
406
602
  // ("a dashboard with a data table") is that family's page, unless it
407
603
  // names far more of the listed template's words.
408
- const order = content.map(stem);
409
- return familyAt(kept, catalog, order) < familyAt(listed, catalog, order) &&
410
- mine >= theirs - FAMILY_SLACK
411
- ? kept
412
- : listed;
604
+ const stays =
605
+ mine >= theirs ||
606
+ (familyAt(kept, catalog, order) < familyAt(listed, catalog, order) &&
607
+ mine >= theirs - FAMILY_SLACK);
608
+ if (!stays) return listed;
609
+ // A tie in the ranker is no preference: every table that names "table"
610
+ // scores the same, and the alphabet must not choose the page. Among the
611
+ // family's templates the ranker ties with this unlisted one, the template
612
+ // whose own descriptor best matches the idea starts (`fullerOfTie`), then
613
+ // the one most typical of the family. Only the templates' descriptors
614
+ // decide this tie, never the tables.
615
+ return fullerOfTie(kept, idea, ranked, cands, catalog);
413
616
  }
414
617
  const top = best(() => true);
415
- if (top !== SHELL) return top;
618
+ if (top !== SHELL)
619
+ return bestPage(idea, ranked, pick, catalog, weights) ?? top;
416
620
  // An idea that asks for a new page keeps the ranker's template rather than
417
621
  // the shell.
418
622
  if (newPage && kept) return kept;
@@ -420,8 +624,9 @@ export function weighStart(
420
624
  }
421
625
 
422
626
  /**
423
- * The blend's scores: the app shell's, and the best non-shell template with
424
- * its score and the runner-up's. Null without weights.
627
+ * The call model's scores: the app shell's, the best non-shell template's and
628
+ * the runner-up's, with the page to start from (the pick model's choice when
629
+ * the file has one, else the call model's best page). Null without weights.
425
630
  * @param {string} idea
426
631
  * @param {import('./rank.mjs').RankedPage[]} ranked
427
632
  * @param {import('./rank.mjs').RankedPage | null} pick
@@ -440,7 +645,9 @@ export function blendSummary(idea, ranked, pick, catalog, weights) {
440
645
  rest.sort((x, y) => y.score - x.score || x.i - y.i);
441
646
  return {
442
647
  shell,
443
- best: rest[0]?.name ?? null,
648
+ best: hasPickModel(weights)
649
+ ? bestPage(idea, ranked, pick, catalog, weights)
650
+ : (rest[0]?.name ?? null),
444
651
  bestScore: rest[0]?.score ?? 0,
445
652
  secondScore: rest[1]?.score ?? 0,
446
653
  };
@@ -0,0 +1,23 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * @file The shape check for `build`'s checked-in word models (spec:AST-048).
6
+ *
7
+ * @input A parsed word model (tables and blend numbers) and the candidate
8
+ * count of its weights file.
9
+ * @output `isWordModel(model, n)`: whether the kit can read it.
10
+ * @position Beside weights.mjs (api/build/kit/). The adapter checks the
11
+ * weights file's call model with it, and weights.mjs checks the optional
12
+ * pick model with it. It imports nothing, so both can use it.
13
+ */
14
+ /**
15
+ * Whether a word model has the shape the kit reads, over `n` candidates: every
16
+ * table row has a weight per candidate, every bias a number per candidate, and
17
+ * the blend has three numbers per member (the tables plus the ranker) and one
18
+ * for the shell. The weights file's call model and its `pick` model share it.
19
+ * @param {any} model
20
+ * @param {number} n the candidate count
21
+ * @returns {boolean}
22
+ */
23
+ export function isWordModel(model: any, n: number): boolean;
@@ -0,0 +1,46 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The shape check for `build`'s checked-in word models (spec:AST-048).
5
+ *
6
+ * @input A parsed word model (tables and blend numbers) and the candidate
7
+ * count of its weights file.
8
+ * @output `isWordModel(model, n)`: whether the kit can read it.
9
+ * @position Beside weights.mjs (api/build/kit/). The adapter checks the
10
+ * weights file's call model with it, and weights.mjs checks the optional
11
+ * pick model with it. It imports nothing, so both can use it.
12
+ */
13
+
14
+ /**
15
+ * Whether a word model has the shape the kit reads, over `n` candidates: every
16
+ * table row has a weight per candidate, every bias a number per candidate, and
17
+ * the blend has three numbers per member (the tables plus the ranker) and one
18
+ * for the shell. The weights file's call model and its `pick` model share it.
19
+ * @param {any} model
20
+ * @param {number} n the candidate count
21
+ * @returns {boolean}
22
+ */
23
+ export function isWordModel(model, n) {
24
+ return (
25
+ n > 0 &&
26
+ Array.isArray(model?.tables) &&
27
+ model.tables.length > 0 &&
28
+ model.tables.every(
29
+ (/** @type {any} */ t) =>
30
+ Array.isArray(t?.words) &&
31
+ Array.isArray(t.rows) &&
32
+ t.rows.length === t.words.length &&
33
+ t.rows.every(
34
+ (/** @type {any} */ r) => typeof r === 'string' && r.length === n,
35
+ ) &&
36
+ Array.isArray(t.bias) &&
37
+ t.bias.length === n &&
38
+ t.bias.every((/** @type {any} */ b) => Number.isFinite(b)) &&
39
+ Number.isFinite(t.clip) &&
40
+ Number.isFinite(t.step),
41
+ ) &&
42
+ Array.isArray(model.blend) &&
43
+ model.blend.length === 3 * (model.tables.length + 1) + 1 &&
44
+ model.blend.every((/** @type {any} */ x) => Number.isFinite(x))
45
+ );
46
+ }
@@ -30,6 +30,47 @@ export function pairsOf(texts: string[]): Set<string>;
30
30
  * @returns {Set<string>}
31
31
  */
32
32
  export function containersOf(query: string): Set<string>;
33
+ /**
34
+ * A template's keywords as the units a request can match, each read with the
35
+ * caller's own word reader. A one-word keyword is that word. A longer keyword
36
+ * is one phrase unit, its words joined by single spaces: a request matches it
37
+ * only when it names those words in that order (`phrasesIn`), and its words
38
+ * never count alone. So "table of contents" on a docs page adds no "table" to
39
+ * that page, and a table request still reads as a table.
40
+ * @param {readonly string[]} keywords
41
+ * @param {(text: string) => string[]} read the caller's word reader
42
+ * @returns {string[]}
43
+ */
44
+ export function keywordUnits(keywords: readonly string[], read: (text: string) => string[]): string[];
45
+ /**
46
+ * The phrase units (two or more words) a request names: the unit's words
47
+ * appear next to each other, in order, in the request's words as the same
48
+ * reader reads them.
49
+ * @param {readonly string[]} words the request's words, in order
50
+ * @param {Iterable<string>} units
51
+ * @returns {Set<string>}
52
+ */
53
+ export function phrasesIn(words: readonly string[], units: Iterable<string>): Set<string>;
54
+ /**
55
+ * The words a template's keyword units give an idea: each one-word keyword,
56
+ * and every word of each phrase keyword the idea names (`phrasesIn`). A named
57
+ * phrase carries all of its words, as the same words listed one by one would;
58
+ * a phrase the idea does not name gives none of them.
59
+ * @param {readonly string[]} units the template's keyword units (`keywordUnits`)
60
+ * @param {readonly string[]} words the idea's words, in order, read the same way
61
+ * @returns {string[]}
62
+ */
63
+ export function keywordWordsFor(units: readonly string[], words: readonly string[]): string[];
64
+ /**
65
+ * What each frame of an idea holds: for every container phrase ("settings in
66
+ * a modal", "in a settings modal"), the frame's terms with the words that
67
+ * name what sits in it: the head of the phrase right before the container
68
+ * phrase, and the container phrase's own other words. In "a toggle in a modal
69
+ * on the settings page" the modal holds the toggle, not the settings page.
70
+ * @param {string} query
71
+ * @returns {Map<string, Set<string>>} frame term -> terms it holds
72
+ */
73
+ export function framesOf(query: string): Map<string, Set<string>>;
33
74
  /**
34
75
  * Family words, from the templates' own ids: a word in the ids of two or more
35
76
  * templates of one family, plus the family's name when a template carries it.
@@ -69,5 +110,6 @@ export type RankedPage = {
69
110
  family: string;
70
111
  base: boolean;
71
112
  matched: Set<string>;
113
+ typical: number;
72
114
  };
73
115
  export type IdeaKind = "page" | "part" | "edit";
@@ -130,6 +130,87 @@ export function containersOf(query) {
130
130
  return found;
131
131
  }
132
132
 
133
+ /**
134
+ * A template's keywords as the units a request can match, each read with the
135
+ * caller's own word reader. A one-word keyword is that word. A longer keyword
136
+ * is one phrase unit, its words joined by single spaces: a request matches it
137
+ * only when it names those words in that order (`phrasesIn`), and its words
138
+ * never count alone. So "table of contents" on a docs page adds no "table" to
139
+ * that page, and a table request still reads as a table.
140
+ * @param {readonly string[]} keywords
141
+ * @param {(text: string) => string[]} read the caller's word reader
142
+ * @returns {string[]}
143
+ */
144
+ export function keywordUnits(keywords, read) {
145
+ return keywords.map(keyword => read(keyword).join(' ')).filter(Boolean);
146
+ }
147
+
148
+ /**
149
+ * The phrase units (two or more words) a request names: the unit's words
150
+ * appear next to each other, in order, in the request's words as the same
151
+ * reader reads them.
152
+ * @param {readonly string[]} words the request's words, in order
153
+ * @param {Iterable<string>} units
154
+ * @returns {Set<string>}
155
+ */
156
+ export function phrasesIn(words, units) {
157
+ const text = ` ${words.join(' ')} `;
158
+ const found = new Set();
159
+ for (const unit of units) {
160
+ if (unit.includes(' ') && text.includes(` ${unit} `)) found.add(unit);
161
+ }
162
+ return found;
163
+ }
164
+
165
+ /**
166
+ * The words a template's keyword units give an idea: each one-word keyword,
167
+ * and every word of each phrase keyword the idea names (`phrasesIn`). A named
168
+ * phrase carries all of its words, as the same words listed one by one would;
169
+ * a phrase the idea does not name gives none of them.
170
+ * @param {readonly string[]} units the template's keyword units (`keywordUnits`)
171
+ * @param {readonly string[]} words the idea's words, in order, read the same way
172
+ * @returns {string[]}
173
+ */
174
+ export function keywordWordsFor(units, words) {
175
+ const named = phrasesIn(words, units);
176
+ return units.flatMap(unit =>
177
+ !unit.includes(' ') ? [unit] : named.has(unit) ? unit.split(' ') : [],
178
+ );
179
+ }
180
+
181
+ /**
182
+ * What each frame of an idea holds: for every container phrase ("settings in
183
+ * a modal", "in a settings modal"), the frame's terms with the words that
184
+ * name what sits in it: the head of the phrase right before the container
185
+ * phrase, and the container phrase's own other words. In "a toggle in a modal
186
+ * on the settings page" the modal holds the toggle, not the settings page.
187
+ * @param {string} query
188
+ * @returns {Map<string, Set<string>>} frame term -> terms it holds
189
+ */
190
+ export function framesOf(query) {
191
+ const text = String(query);
192
+ /** @type {Map<string, Set<string>>} */
193
+ const held = new Map();
194
+ for (const m of text.matchAll(CONTAINER_PHRASE)) {
195
+ const frames = terms(`${m[1]} ${m[2] ?? ''}`).filter(t =>
196
+ OVERLAY_FRAMES.has(t),
197
+ );
198
+ if (frames.length === 0) continue;
199
+ const before = text.slice(0, m.index).toLowerCase().split(PHRASE_END);
200
+ const lead = terms(before[before.length - 1] ?? '');
201
+ const holds = new Set([
202
+ ...lead.slice(-1),
203
+ ...terms(`${m[1]} ${m[2] ?? ''}`).filter(t => !OVERLAY_FRAMES.has(t)),
204
+ ]);
205
+ for (const f of frames) {
206
+ const set = held.get(f) ?? new Set();
207
+ for (const t of holds) set.add(t);
208
+ held.set(f, set);
209
+ }
210
+ }
211
+ return held;
212
+ }
213
+
133
214
  /** @param {string} text */
134
215
  export const normalized = text =>
135
216
  (
@@ -163,7 +244,7 @@ export const SYNONYMS_OF = (() => {
163
244
  /**
164
245
  * @typedef {import('../_adapter.mjs').PageTemplate} PageTemplate
165
246
  * @typedef {import('../_adapter.mjs').ComponentWords} ComponentWords
166
- * @typedef {{name: string, score: number, hits: number, familyNamed: boolean, headNamed: boolean, containerMatched: boolean, family: string, base: boolean, matched: Set<string>}} RankedPage
247
+ * @typedef {{name: string, score: number, hits: number, familyNamed: boolean, headNamed: boolean, containerMatched: boolean, family: string, base: boolean, matched: Set<string>, typical: number}} RankedPage
167
248
  * @typedef {'page' | 'part' | 'edit'} IdeaKind
168
249
  */
169
250
 
@@ -27,7 +27,6 @@ InputGroupInternalContext InputGroupInternalContext InputGroup/InputGroup.doc.mj
27
27
  InternationalizationContext InternationalizationContext i18n/InternationalizationProvider.doc.mjs i18n/InternationalizationContext.ts
28
28
  ItemDescriptionContext ItemDescriptionContext Item/Item.doc.mjs Item/ItemDescriptionContext.tsx
29
29
  ItemMarkerColumnsContext ItemMarkerColumnsContext Item/Item.doc.mjs Item/ItemMarkerColumnsContext.tsx
30
- ItemSwipeLayer ItemSwipeLayer Item/Item.doc.mjs Item/ItemSwipeLayer.tsx
31
30
  LayerContext LayerContext Layer/Layer.doc.mjs Layer/LayerContext.ts
32
31
  LayerDepthContext LayerDepthContext Layer/Layer.doc.mjs Layer/LayerDepthContext.tsx
33
32
  LayerProvider LayerProvider Layer/Layer.doc.mjs Layer/LayerProvider.tsx
@@ -111,7 +110,7 @@ dataTokens dataTokens theme/MediaTheme.doc.mjs theme/domainTokens/dataTokens.ts
111
110
  dayCellUtils dayCellUtils Calendar/Calendar.doc.mjs Calendar/dayCellUtils.ts
112
111
  declarationBoundary declarationBoundary theme/MediaTheme.doc.mjs theme/declarationBoundary.ts
113
112
  defaultIcons defaultIcons Icon/Icon.doc.mjs Icon/defaultIcons.tsx
114
- defineSyntaxTheme defineSyntaxTheme theme/MediaTheme.doc.mjs theme/syntax/defineSyntaxTheme.ts
113
+ defineSyntaxTheme defineSyntaxTheme theme/syntax/useSyntaxTheme.doc.mjs theme/syntax/defineSyntaxTheme.ts
115
114
  defineTheme defineTheme theme/MediaTheme.doc.mjs theme/defineTheme.ts
116
115
  derivedVarRegistry derivedVarRegistry theme/MediaTheme.doc.mjs theme/derivedVarRegistry.ts
117
116
  dockerfile dockerfile CodeBlock/CodeBlock.doc.mjs CodeBlock/languages/dockerfile.ts
@@ -191,7 +190,7 @@ popoverOperations popoverOperations Layer/Layer.doc.mjs Layer/popoverOperations.
191
190
  powerSearchSheetUtils powerSearchSheetUtils PowerSearch/PowerSearch.doc.mjs PowerSearch/powerSearchSheetUtils.ts
192
191
  powershell powershell CodeBlock/CodeBlock.doc.mjs CodeBlock/languages/powershell.ts
193
192
  preserveAnimations preserveAnimations Layer/Layer.doc.mjs Layer/preserveAnimations.ts
194
- presets presets theme/MediaTheme.doc.mjs theme/syntax/presets.ts
193
+ presets presets theme/syntax/useSyntaxTheme.doc.mjs theme/syntax/presets.ts
195
194
  pressGroupContext pressGroupContext hooks/useAnimatedLayout.doc.mjs hooks/pressGroupContext.ts
196
195
  protocol protocol Markdown/Markdown.doc.mjs Markdown/plugins/protocol.ts
197
196
  publicContext publicContext i18n/InternationalizationProvider.doc.mjs i18n/publicContext.ts
@@ -251,7 +250,7 @@ useCalendarConstraints useCalendarConstraints Calendar/useCalendarConstraints.do
251
250
  useCalendarDays useCalendarDays Calendar/useCalendarDays.doc.mjs Calendar/hooks/useCalendarDays.ts
252
251
  useCalendarNavigation useCalendarNavigation Calendar/useCalendarNavigation.doc.mjs Calendar/hooks/useCalendarNavigation.ts
253
252
  useChatComposerTokens useChatComposerTokens Chat/Chat.doc.mjs Chat/useChatComposerTokens.ts
254
- useChatDictation useChatDictation Chat/Chat.doc.mjs Chat/useChatDictation.ts
253
+ useChatDictation useChatDictation Chat/useChatDictation.doc.mjs Chat/useChatDictation.ts
255
254
  useChatNewMessages useChatNewMessages Chat/Chat.doc.mjs Chat/useChatNewMessages.ts
256
255
  useChatPasteAsToken useChatPasteAsToken Chat/Chat.doc.mjs Chat/useChatPasteAsToken.ts
257
256
  useChatStreamScroll useChatStreamScroll Chat/Chat.doc.mjs Chat/useChatStreamScroll.ts
@@ -295,7 +294,7 @@ useSettledOpen useSettledOpen hooks/useAnimatedLayout.doc.mjs hooks/useSettledOp
295
294
  useSheetGestures useSheetGestures BottomSheet/BottomSheet.doc.mjs BottomSheet/useSheetGestures.ts
296
295
  useSliderTouch useSliderTouch Slider/Slider.doc.mjs Slider/useSliderTouch.ts
297
296
  useSpeechRecognition useSpeechRecognition Chat/Chat.doc.mjs Chat/useSpeechRecognition.ts
298
- useSwipeAction useSwipeAction Item/Item.doc.mjs Item/useSwipeAction.ts
297
+ useSwipeAction useSwipeAction Swipe/createSwipe.doc.mjs Swipe/useSwipeAction.ts
299
298
  useSwitchTouch useSwitchTouch Switch/Switch.doc.mjs Switch/useSwitchTouch.ts
300
299
  useTableCellStyles useTableCellStyles Table/Table.doc.mjs Table/useTableCellStyles.ts
301
300
  useTableColumnSettingsState useTableColumnSettingsState Table/plugins/columnSettings/useTableColumnSettingsState.doc.mjs Table/plugins/columnSettings/useTableColumnSettingsState.tsx
@@ -15,7 +15,7 @@
15
15
  * @param {string|null} opts.lang
16
16
  * @returns {Promise<ComponentListResponse>}
17
17
  */
18
- export function componentList(coreDir: string, { cwd, category, detail, zh, dense, lang }: {
18
+ export function componentList(coreDir: string, opts: {
19
19
  cwd: string;
20
20
  category?: string | undefined;
21
21
  detail: "full" | "compact" | "brief";