@astryxdesign/cli 0.7.16 → 0.7.17-canary.g16fe6a8

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 (380) hide show
  1. package/README.md +76 -86
  2. package/api/build/_adapter.d.mts +12 -0
  3. package/api/build/_adapter.mjs +51 -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 +4 -3
  7. package/api/build/build.type.d.mts +2 -2
  8. package/api/build/build.type.mjs +3 -3
  9. package/api/build/kit/kind.d.mts +2 -1
  10. package/api/build/kit/kind.mjs +199 -10
  11. package/api/build/kit/kit.mjs +6 -4
  12. package/api/build/kit/rank.d.mts +4 -2
  13. package/api/build/kit/rank.mjs +125 -24
  14. package/api/build/kit/start.d.mts +5 -4
  15. package/api/build/kit/start.mjs +12 -8
  16. package/api/build/kit/weights.d.mts +39 -3
  17. package/api/build/kit/weights.json +1 -1
  18. package/api/build/kit/weights.mjs +340 -43
  19. package/api/build/kit/word-model.d.mts +23 -0
  20. package/api/build/kit/word-model.mjs +46 -0
  21. package/api/build/kit/words.d.mts +48 -0
  22. package/api/build/kit/words.mjs +90 -1
  23. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  24. package/api/component/list/list.d.mts +1 -1
  25. package/api/component/list/list.mjs +48 -6
  26. package/api/discover/_adapter.d.mts +1 -1
  27. package/api/discover/search/search.mjs +3 -2
  28. package/api/docs/_adapter.d.mts +28 -2
  29. package/api/docs/_adapter.mjs +249 -10
  30. package/api/docs/docs.d.mts +3 -0
  31. package/api/docs/docs.doc.mjs +7 -1
  32. package/api/docs/docs.mjs +12 -0
  33. package/api/docs/docs.type.d.mts +5 -0
  34. package/api/docs/docs.type.mjs +2 -0
  35. package/api/docs/node/node.mjs +1 -1
  36. package/api/doctor/_adapter.d.mts +27 -5
  37. package/api/doctor/_adapter.mjs +83 -10
  38. package/api/doctor/built-checks.mjs +40 -14
  39. package/api/doctor/doctor.d.mts +4 -3
  40. package/api/doctor/doctor.mjs +14 -7
  41. package/api/doctor/theme-checks.mjs +121 -17
  42. package/api/icon/_records.mjs +2 -1
  43. package/api/index.d.mts +2 -0
  44. package/api/index.mjs +2 -0
  45. package/api/integration/_adapter.d.mts +44 -0
  46. package/api/integration/_adapter.mjs +77 -1
  47. package/api/integration/authoring-checks.mjs +6 -6
  48. package/api/integration/example-scope.d.mts +14 -0
  49. package/api/integration/example-scope.mjs +44 -0
  50. package/api/integration/example-scope.type.d.mts +29 -0
  51. package/api/integration/example-scope.type.mjs +25 -0
  52. package/api/integration/integrationExampleScope.doc.d.mts +11 -0
  53. package/api/integration/integrationExampleScope.doc.mjs +59 -0
  54. package/api/integration/validate-integration.mjs +19 -1
  55. package/api/integration/validate-integration.type.d.mts +9 -0
  56. package/api/integration/validate-integration.type.mjs +1 -1
  57. package/api/integration/validateIntegration.doc.mjs +1 -1
  58. package/api/render/_adapter.mjs +591 -195
  59. package/api/render/render.doc.mjs +11 -3
  60. package/api/render/render.type.d.mts +52 -0
  61. package/api/render/render.type.mjs +31 -1
  62. package/api/search/ORDERING.md +1 -1
  63. package/api/search/_adapter.d.mts +9 -0
  64. package/api/search/_adapter.mjs +85 -0
  65. package/api/search/_candidate-score.mjs +51 -32
  66. package/api/search/_fit-order.mjs +3 -3
  67. package/api/search/_gather-components.d.mts +3 -2
  68. package/api/search/_gather-components.mjs +12 -3
  69. package/api/search/_lexical.d.mts +5 -0
  70. package/api/search/_lexical.mjs +8 -2
  71. package/api/search/_result.d.mts +11 -9
  72. package/api/search/_result.mjs +4 -4
  73. package/api/search/_score.d.mts +6 -1
  74. package/api/search/_score.mjs +15 -3
  75. package/api/search/search-index.mjs +7 -1
  76. package/api/search/search.d.mts +1 -1
  77. package/api/theme/_adapter.mjs +12 -1
  78. package/api/theme/build/build.d.mts +132 -1
  79. package/api/theme/build/build.mjs +482 -157
  80. package/api/theme/build/core-interception.d.mts +10 -0
  81. package/api/theme/build/core-interception.mjs +10 -0
  82. package/api/theme/build/font-warning.d.mts +44 -5
  83. package/api/theme/build/font-warning.mjs +118 -10
  84. package/api/theme/build/icon-imports.mjs +51 -9
  85. package/api/theme/theme.type.d.mts +10 -0
  86. package/api/theme/theme.type.mjs +7 -1
  87. package/api/theme-edit/_adapter.d.mts +115 -4
  88. package/api/theme-edit/_adapter.mjs +997 -83
  89. package/api/theme-edit/_catalog.d.mts +20 -2
  90. package/api/theme-edit/_catalog.mjs +50 -10
  91. package/api/theme-edit/_check.d.mts +75 -24
  92. package/api/theme-edit/_check.mjs +2672 -422
  93. package/api/theme-edit/_color.d.mts +10 -0
  94. package/api/theme-edit/_color.mjs +54 -1
  95. package/api/theme-edit/_compiler.d.mts +1 -0
  96. package/api/theme-edit/_compiler.mjs +133 -15
  97. package/api/theme-edit/_context.d.mts +14 -3
  98. package/api/theme-edit/_context.mjs +225 -65
  99. package/api/theme-edit/_css.d.mts +14 -0
  100. package/api/theme-edit/_css.mjs +46 -1
  101. package/api/theme-edit/_edit.d.mts +54 -4
  102. package/api/theme-edit/_edit.mjs +2966 -286
  103. package/api/theme-edit/_how-commands.d.mts +72 -1
  104. package/api/theme-edit/_how-commands.mjs +770 -9
  105. package/api/theme-edit/_how-question.d.mts +82 -5
  106. package/api/theme-edit/_how-question.mjs +6983 -701
  107. package/api/theme-edit/_how.d.mts +2 -1
  108. package/api/theme-edit/_how.mjs +237 -41
  109. package/api/theme-edit/_importers.d.mts +38 -0
  110. package/api/theme-edit/_importers.mjs +188 -0
  111. package/api/theme-edit/_marks.d.mts +31 -5
  112. package/api/theme-edit/_marks.mjs +57 -5
  113. package/api/theme-edit/_name-rule.d.mts +11 -0
  114. package/api/theme-edit/_name-rule.mjs +12 -0
  115. package/api/theme-edit/_normal.d.mts +303 -0
  116. package/api/theme-edit/_normal.mjs +1517 -0
  117. package/api/theme-edit/_palette.d.mts +12 -0
  118. package/api/theme-edit/_palette.mjs +37 -4
  119. package/api/theme-edit/_part-words.d.mts +31 -0
  120. package/api/theme-edit/_part-words.mjs +126 -0
  121. package/api/theme-edit/_parts.d.mts +28 -2
  122. package/api/theme-edit/_parts.mjs +267 -31
  123. package/api/theme-edit/_preview-app.d.mts +7 -13
  124. package/api/theme-edit/_preview-app.mjs +814 -406
  125. package/api/theme-edit/_preview.d.mts +116 -16
  126. package/api/theme-edit/_preview.mjs +649 -152
  127. package/api/theme-edit/_project.d.mts +22 -1
  128. package/api/theme-edit/_project.mjs +83 -3
  129. package/api/theme-edit/_settings.d.mts +467 -42
  130. package/api/theme-edit/_settings.mjs +3527 -468
  131. package/api/theme-edit/_tables.d.mts +21 -0
  132. package/api/theme-edit/_tables.mjs +97 -3
  133. package/api/theme-edit/_vet.d.mts +31 -0
  134. package/api/theme-edit/_vet.mjs +114 -8
  135. package/api/theme-edit/theme-edit.type.d.mts +16 -2
  136. package/api/theme-edit/theme-edit.type.mjs +6 -3
  137. package/api/theme-edit/themeEditHow.doc.mjs +1 -1
  138. package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
  139. package/api/theme-edit/themeEditNew.doc.mjs +7 -4
  140. package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
  141. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
  142. package/api/upgrade/run/run.mjs +4 -3
  143. package/assets/codemods/integration-discovery.mjs +2 -1
  144. package/assets/codemods/run-codemod.mjs +87 -7
  145. package/assets/codemods/transforms/next/index.mjs +11 -1
  146. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  147. package/assets/component-list.generated.json +1 -0
  148. package/assets/docs/author-a-theme.doc.mjs +1 -0
  149. package/assets/docs/theme.doc.dense.mjs +2 -2
  150. package/assets/docs/theme.doc.mjs +1 -1
  151. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  152. package/assets/docs/tree/checks.doc.mjs +1 -1
  153. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  154. package/assets/docs/tree/render-pages.doc.mjs +44 -3
  155. package/assets/docs/tree/share-a-page.doc.mjs +157 -0
  156. package/assets/docs/tree/single-component.doc.mjs +4 -0
  157. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  158. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  159. package/assets/docs/use-a-theme.doc.mjs +1 -1
  160. package/assets/docs.generated.json +2 -2
  161. package/assets/search-catalog.generated.json +2 -0
  162. package/assets/self-audit.generated.json +1 -1
  163. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  164. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  165. package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
  166. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  167. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  168. package/assets/templates/components.generated.json +1 -1
  169. package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
  170. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
  171. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  172. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  173. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  174. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  175. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  176. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  177. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  178. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  179. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  180. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  181. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  182. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  183. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  184. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  185. package/assets/templates/pages/editor/template.doc.mjs +2 -8
  186. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  187. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  188. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  189. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  190. package/assets/templates/pages/ide/page.tsx +24 -2
  191. package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
  192. package/assets/templates/pages/library/template.doc.mjs +4 -1
  193. package/assets/templates/pages/login/template.doc.mjs +2 -1
  194. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  195. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  196. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  197. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  198. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  199. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  200. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  201. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  202. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  203. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  204. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  205. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  206. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  207. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  208. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  209. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  210. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
  211. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  212. package/assets/theme.template.ts +6 -0
  213. package/authoring/debug/parse.d.mts +3 -3
  214. package/authoring/doctypes/_schema.d.mts +3 -3
  215. package/authoring/doctypes/command/command.doc.mjs +1 -1
  216. package/authoring/doctypes/component/categories.d.mts +37 -0
  217. package/authoring/doctypes/component/categories.mjs +54 -0
  218. package/authoring/doctypes/template/template.doc.mjs +1 -1
  219. package/authoring/doctypes/template/type.ts +9 -0
  220. package/authoring/example/example.doc.d.mts +12 -0
  221. package/authoring/example/example.doc.mjs +69 -0
  222. package/authoring/example/preview.d.mts +92 -0
  223. package/authoring/example/preview.mjs +994 -0
  224. package/authoring/example/type.ts +102 -0
  225. package/authoring/index.d.mts +1 -0
  226. package/authoring/index.d.ts +12 -0
  227. package/authoring/index.mjs +3 -1
  228. package/clients/cli/bin/astryx.mjs +6 -9
  229. package/clients/cli/build-id.generated.json +1 -1
  230. package/clients/cli/commands/component.doc.mjs +1 -1
  231. package/clients/cli/commands/component.mjs +22 -3
  232. package/clients/cli/commands/docs.doc.mjs +7 -1
  233. package/clients/cli/commands/docs.mjs +3 -1
  234. package/clients/cli/commands/doctor.mjs +32 -14
  235. package/clients/cli/commands/experimental/render.mjs +42 -1
  236. package/clients/cli/commands/experimental/theme.mjs +573 -119
  237. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  238. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  239. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
  240. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
  241. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
  242. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  243. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  244. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  245. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  246. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
  247. package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
  248. package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
  249. package/clients/cli/commands/search.doc.mjs +2 -1
  250. package/clients/cli/commands/search.mjs +6 -1
  251. package/clients/cli/commands/template.mjs +4 -2
  252. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  253. package/clients/cli/commands/theme.doc.mjs +1 -1
  254. package/clients/cli/commands/theme.mjs +718 -438
  255. package/clients/cli/commands/upgrade.mjs +42 -7
  256. package/clients/cli/index.mjs +1 -1
  257. package/clients/cli/lib/cli-error.mjs +2 -1
  258. package/clients/cli/lib/component-format.mjs +205 -98
  259. package/clients/cli/lib/hook-format.mjs +9 -19
  260. package/clients/cli/lib/json-shim.mjs +132 -24
  261. package/clients/cli/lib/manifest.mjs +3 -2
  262. package/clients/cli/manifest.generated.json +1 -1
  263. package/foundation/agent-docs/agent-docs.mjs +1 -1
  264. package/foundation/config/theme-state.d.mts +13 -1
  265. package/foundation/config/theme-state.mjs +47 -7
  266. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  267. package/foundation/discovery/component-discovery.d.mts +11 -0
  268. package/foundation/discovery/component-discovery.mjs +56 -8
  269. package/foundation/discovery/component-replacement.mjs +130 -1
  270. package/foundation/discovery/copied-passages.mjs +2 -1
  271. package/foundation/discovery/core-component-docs.d.mts +29 -0
  272. package/foundation/discovery/core-component-docs.mjs +83 -0
  273. package/foundation/discovery/doc-types.mjs +4 -3
  274. package/foundation/discovery/entry-name-files.d.mts +43 -0
  275. package/foundation/discovery/entry-name-files.mjs +264 -0
  276. package/foundation/discovery/hook-discovery.d.mts +8 -2
  277. package/foundation/discovery/hook-discovery.mjs +22 -8
  278. package/foundation/discovery/icon-definition-discovery.mjs +2 -1
  279. package/foundation/discovery/icon-set-checks.mjs +2 -1
  280. package/foundation/discovery/icon-set-discovery.mjs +2 -1
  281. package/foundation/discovery/integration-doc-files.mjs +2 -1
  282. package/foundation/discovery/package-exports.d.mts +10 -0
  283. package/foundation/discovery/package-exports.mjs +56 -3
  284. package/foundation/discovery/prop-drift.mjs +9 -9
  285. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  286. package/foundation/discovery/runner-allowlist.mjs +2 -0
  287. package/foundation/discovery/stored-component-list.d.mts +43 -0
  288. package/foundation/discovery/stored-component-list.mjs +90 -0
  289. package/foundation/discovery/stored-search-catalog.d.mts +115 -0
  290. package/foundation/discovery/stored-search-catalog.mjs +297 -0
  291. package/foundation/discovery/stored-self-audit.d.mts +26 -10
  292. package/foundation/discovery/stored-self-audit.mjs +38 -18
  293. package/foundation/discovery/template-adapter.d.mts +53 -1
  294. package/foundation/discovery/template-adapter.mjs +176 -12
  295. package/foundation/discovery/template-icons.mjs +2 -1
  296. package/foundation/discovery/theme-discovery.mjs +31 -4
  297. package/foundation/discovery/theme-imports.d.mts +14 -0
  298. package/foundation/discovery/theme-imports.mjs +43 -1
  299. package/foundation/discovery/theming-targets.d.mts +6 -5
  300. package/foundation/discovery/theming-targets.mjs +31 -47
  301. package/foundation/doc-compiler/import.mjs +7 -1
  302. package/foundation/doc-compiler/inputs.mjs +3 -2
  303. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  304. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  305. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  306. package/foundation/env/semver.mjs +3 -1
  307. package/foundation/fonts/font-stylesheet.d.mts +38 -0
  308. package/foundation/fonts/font-stylesheet.mjs +141 -0
  309. package/foundation/fs/cache-eviction.d.mts +21 -0
  310. package/foundation/fs/cache-eviction.mjs +73 -0
  311. package/foundation/fs/exact-codec.d.mts +12 -2
  312. package/foundation/fs/exact-codec.mjs +23 -6
  313. package/foundation/fs/file-protection.mjs +4 -3
  314. package/foundation/fs/gather-cache.d.mts +62 -4
  315. package/foundation/fs/gather-cache.mjs +517 -91
  316. package/foundation/fs/jiti-cache.d.mts +19 -1
  317. package/foundation/fs/jiti-cache.mjs +130 -6
  318. package/foundation/fs/kept-tree.d.mts +60 -0
  319. package/foundation/fs/kept-tree.mjs +154 -0
  320. package/foundation/fs/listing-cache.d.mts +7 -0
  321. package/foundation/fs/listing-cache.mjs +10 -0
  322. package/foundation/fs/module-loader.d.mts +24 -2
  323. package/foundation/fs/module-loader.mjs +94 -21
  324. package/foundation/fs/paths.d.mts +18 -0
  325. package/foundation/fs/paths.mjs +15 -2
  326. package/foundation/fs/read-record.d.mts +9 -0
  327. package/foundation/fs/read-record.mjs +19 -11
  328. package/foundation/fs/stop-cleanup.d.mts +12 -0
  329. package/foundation/fs/stop-cleanup.mjs +66 -0
  330. package/foundation/identity/provider-identity.d.mts +6 -0
  331. package/foundation/identity/provider-identity.mjs +10 -1
  332. package/foundation/integrations/contribution-inventory.mjs +4 -3
  333. package/foundation/integrations/example-code.d.mts +63 -0
  334. package/foundation/integrations/example-code.mjs +416 -0
  335. package/foundation/integrations/public-imports.d.mts +9 -0
  336. package/foundation/integrations/public-imports.mjs +3 -2
  337. package/foundation/integrations/validate-contributions.mjs +17 -45
  338. package/foundation/render/embedded-files.d.mts +6 -0
  339. package/foundation/render/embedded-files.mjs +25 -5
  340. package/foundation/render/embedded-imports.d.mts +39 -7
  341. package/foundation/render/embedded-imports.mjs +66 -27
  342. package/foundation/render/file-header.d.mts +66 -0
  343. package/foundation/render/file-header.mjs +118 -0
  344. package/foundation/render/host-answer.d.mts +18 -0
  345. package/foundation/render/host-answer.mjs +46 -0
  346. package/foundation/render/host-exit.d.mts +1 -0
  347. package/foundation/render/host-exit.mjs +6 -1
  348. package/foundation/render/html-reader.d.mts +55 -2
  349. package/foundation/render/html-reader.mjs +145 -26
  350. package/foundation/render/markup-edits.d.mts +57 -0
  351. package/foundation/render/markup-edits.mjs +182 -0
  352. package/foundation/render/page-host.mjs +29 -12
  353. package/foundation/render/page-worker.mjs +121 -13
  354. package/foundation/render/picture-chrome.d.mts +4 -0
  355. package/foundation/render/picture-chrome.mjs +185 -0
  356. package/foundation/render/picture-playwright.d.mts +4 -0
  357. package/foundation/render/picture-playwright.mjs +34 -0
  358. package/foundation/render/rebuild.mjs +2 -1
  359. package/foundation/render/render-page.d.mts +35 -3
  360. package/foundation/render/render-page.mjs +641 -96
  361. package/foundation/render/source-block.d.mts +85 -6
  362. package/foundation/render/source-block.mjs +211 -20
  363. package/foundation/render/ts-paths.d.mts +69 -6
  364. package/foundation/render/ts-paths.mjs +326 -40
  365. package/foundation/response/error-codes.d.mts +3 -1
  366. package/foundation/response/error-codes.d.ts +1 -0
  367. package/foundation/response/error-codes.doc.mjs +12 -1
  368. package/foundation/response/error-codes.mjs +11 -1
  369. package/foundation/response/response-types.doc.mjs +2 -2
  370. package/foundation/text/compare-text.d.mts +14 -0
  371. package/foundation/text/compare-text.mjs +68 -0
  372. package/foundation/text/css-escape.d.mts +18 -0
  373. package/foundation/text/css-escape.mjs +35 -0
  374. package/foundation/text/string-utils.d.mts +3 -2
  375. package/foundation/text/string-utils.mjs +18 -4
  376. package/foundation/text/suggest-order.d.mts +9 -0
  377. package/foundation/text/suggest-order.mjs +15 -1
  378. package/foundation/xle/expand.mjs +2 -1
  379. package/host/index.mjs +8 -6
  380. package/package.json +7 -6
@@ -47,6 +47,14 @@ export const SHELL_FAMILY = 'Shell';
47
47
  export const CONTAINER_PHRASE =
48
48
  /\b(?:in|inside|within)\s+(?:a|an|the)\s+([a-z-]+)(?:\s+([a-z-]+))?/gi;
49
49
 
50
+ /**
51
+ * A place phrase: a preposition of place, then a determiner ("above the
52
+ * table", "into my dashboard"). CONTAINER_PHRASE is the narrower class of
53
+ * frames a page lives in ("in a modal"); this one names where a piece goes.
54
+ */
55
+ export const PLACE_PHRASE =
56
+ /\b(?:to|into|onto|in|inside|within|on|above|below|beside|under|next to)\s+(?:the|a|an|my|our|this|each|every|existing)\b/i;
57
+
50
58
  /**
51
59
  * Where a phrase ends, for finding the word that heads it: punctuation and
52
60
  * the words that join phrases.
@@ -130,6 +138,87 @@ export function containersOf(query) {
130
138
  return found;
131
139
  }
132
140
 
141
+ /**
142
+ * A template's keywords as the units a request can match, each read with the
143
+ * caller's own word reader. A one-word keyword is that word. A longer keyword
144
+ * is one phrase unit, its words joined by single spaces: a request matches it
145
+ * only when it names those words in that order (`phrasesIn`), and its words
146
+ * never count alone. So "table of contents" on a docs page adds no "table" to
147
+ * that page, and a table request still reads as a table.
148
+ * @param {readonly string[]} keywords
149
+ * @param {(text: string) => string[]} read the caller's word reader
150
+ * @returns {string[]}
151
+ */
152
+ export function keywordUnits(keywords, read) {
153
+ return keywords.map(keyword => read(keyword).join(' ')).filter(Boolean);
154
+ }
155
+
156
+ /**
157
+ * The phrase units (two or more words) a request names: the unit's words
158
+ * appear next to each other, in order, in the request's words as the same
159
+ * reader reads them.
160
+ * @param {readonly string[]} words the request's words, in order
161
+ * @param {Iterable<string>} units
162
+ * @returns {Set<string>}
163
+ */
164
+ export function phrasesIn(words, units) {
165
+ const text = ` ${words.join(' ')} `;
166
+ const found = new Set();
167
+ for (const unit of units) {
168
+ if (unit.includes(' ') && text.includes(` ${unit} `)) found.add(unit);
169
+ }
170
+ return found;
171
+ }
172
+
173
+ /**
174
+ * The words a template's keyword units give an idea: each one-word keyword,
175
+ * and every word of each phrase keyword the idea names (`phrasesIn`). A named
176
+ * phrase carries all of its words, as the same words listed one by one would;
177
+ * a phrase the idea does not name gives none of them.
178
+ * @param {readonly string[]} units the template's keyword units (`keywordUnits`)
179
+ * @param {readonly string[]} words the idea's words, in order, read the same way
180
+ * @returns {string[]}
181
+ */
182
+ export function keywordWordsFor(units, words) {
183
+ const named = phrasesIn(words, units);
184
+ return units.flatMap(unit =>
185
+ !unit.includes(' ') ? [unit] : named.has(unit) ? unit.split(' ') : [],
186
+ );
187
+ }
188
+
189
+ /**
190
+ * What each frame of an idea holds: for every container phrase ("settings in
191
+ * a modal", "in a settings modal"), the frame's terms with the words that
192
+ * name what sits in it: the head of the phrase right before the container
193
+ * phrase, and the container phrase's own other words. In "a toggle in a modal
194
+ * on the settings page" the modal holds the toggle, not the settings page.
195
+ * @param {string} query
196
+ * @returns {Map<string, Set<string>>} frame term -> terms it holds
197
+ */
198
+ export function framesOf(query) {
199
+ const text = String(query);
200
+ /** @type {Map<string, Set<string>>} */
201
+ const held = new Map();
202
+ for (const m of text.matchAll(CONTAINER_PHRASE)) {
203
+ const frames = terms(`${m[1]} ${m[2] ?? ''}`).filter(t =>
204
+ OVERLAY_FRAMES.has(t),
205
+ );
206
+ if (frames.length === 0) continue;
207
+ const before = text.slice(0, m.index).toLowerCase().split(PHRASE_END);
208
+ const lead = terms(before[before.length - 1] ?? '');
209
+ const holds = new Set([
210
+ ...lead.slice(-1),
211
+ ...terms(`${m[1]} ${m[2] ?? ''}`).filter(t => !OVERLAY_FRAMES.has(t)),
212
+ ]);
213
+ for (const f of frames) {
214
+ const set = held.get(f) ?? new Set();
215
+ for (const t of holds) set.add(t);
216
+ held.set(f, set);
217
+ }
218
+ }
219
+ return held;
220
+ }
221
+
133
222
  /** @param {string} text */
134
223
  export const normalized = text =>
135
224
  (
@@ -163,7 +252,7 @@ export const SYNONYMS_OF = (() => {
163
252
  /**
164
253
  * @typedef {import('../_adapter.mjs').PageTemplate} PageTemplate
165
254
  * @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
255
+ * @typedef {{name: string, score: number, hits: number, familyNamed: boolean, headNamed: boolean, containerMatched: boolean, family: string, base: boolean, matched: Set<string>, typical: number}} RankedPage
167
256
  * @typedef {'page' | 'part' | 'edit'} IdeaKind
168
257
  */
169
258
 
@@ -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";
@@ -22,7 +22,9 @@ import {
22
22
  resolveImportPath,
23
23
  resolveIntegrationImportPath,
24
24
  } from '../../../foundation/discovery/component-discovery.mjs';
25
- import {discoverExternalPackages} from '../../../foundation/fs/paths.mjs';
25
+ import {EXACT_CODEC} from '../../../foundation/fs/exact-codec.mjs';
26
+ import {persistedGather} from '../../../foundation/fs/gather-cache.mjs';
27
+ import {CLI_ROOT, discoverExternalPackages, realDir} from '../../../foundation/fs/paths.mjs';
26
28
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
27
29
  import {AstryxError} from '../../error.mjs';
28
30
  import {
@@ -31,6 +33,7 @@ import {
31
33
  loadIntegrationsSafely,
32
34
  withOwnership,
33
35
  } from '../_adapter.mjs';
36
+ import {compareText} from '../../../foundation/text/compare-text.mjs';
34
37
 
35
38
  /**
36
39
  * @typedef {import('../component.type.mjs').ComponentListResponse} ComponentListResponse
@@ -162,10 +165,49 @@ async function replacementEntry(replacement, detail, {zh, dense, lang}) {
162
165
  * @param {string|null} opts.lang
163
166
  * @returns {Promise<ComponentListResponse>}
164
167
  */
165
- export async function componentList(
166
- coreDir,
167
- {cwd, category, detail, zh, dense, lang},
168
- ) {
168
+ export async function componentList(coreDir, opts) {
169
+ const {cwd, category, detail, zh, dense, lang} = opts;
170
+ // A function of the files it reads (Core's component folders and docs, the
171
+ // integrations and their docs), which the kept gather stamps: a later run
172
+ // with every one unchanged reads the list back.
173
+ return /** @type {ComponentListResponse} */ (
174
+ await persistedGather(
175
+ [
176
+ 'component-list',
177
+ realDir(cwd),
178
+ coreDir,
179
+ CLI_ROOT,
180
+ category ?? null,
181
+ detail,
182
+ zh,
183
+ dense,
184
+ lang,
185
+ ],
186
+ () => componentListNow(coreDir, opts),
187
+ COMPONENT_LIST_CODEC,
188
+ )
189
+ );
190
+ }
191
+
192
+ /** The component list, kept exactly, with the envelope's shape. */
193
+ const COMPONENT_LIST_CODEC = {
194
+ ...EXACT_CODEC,
195
+ valid: (/** @type {any} */ value) =>
196
+ value != null &&
197
+ value.type === 'component.list' &&
198
+ value.data != null &&
199
+ typeof value.data.detail === 'string' &&
200
+ value.data.components != null &&
201
+ typeof value.data.components === 'object',
202
+ };
203
+
204
+ /**
205
+ * componentList, worked out now.
206
+ * @param {string} coreDir
207
+ * @param {Parameters<typeof componentList>[1]} options
208
+ * @returns {Promise<ComponentListResponse>}
209
+ */
210
+ async function componentListNow(coreDir, {cwd, category, detail, zh, dense, lang}) {
169
211
  const components = discoverComponents(coreDir);
170
212
  // An active integration replacement takes its Core component's slot in
171
213
  // every list view (spec:AST-035 FR11); the Core original stays reachable
@@ -429,7 +471,7 @@ export async function componentList(
429
471
  });
430
472
  }
431
473
  for (const [key, members] of byGroup) {
432
- members.sort((a, b) => a.name.localeCompare(b.name));
474
+ members.sort((a, b) => compareText(a.name, b.name));
433
475
  listData[key] = members;
434
476
  }
435
477
  }
@@ -216,7 +216,7 @@ export const OFFICIAL_LIST_FILE: string;
216
216
  */
217
217
  export const EXPERIMENTAL_KINDS: readonly ["icon-set"];
218
218
  /** The item kinds every project reads: the catalog kinds, less experimental ones. */
219
- export const STABLE_KINDS: ("template" | "component" | "doc" | "theme" | "codemod" | "agent-doc" | "icon-set")[];
219
+ export const STABLE_KINDS: ("component" | "template" | "doc" | "theme" | "codemod" | "agent-doc" | "icon-set")[];
220
220
  /** The list and detail entry fields for each item kind, in display order. */
221
221
  export const KIND_FIELDS: readonly [readonly ["component", "components"], readonly ["template", "templates"], readonly ["doc", "docs"], readonly ["theme", "themes"], readonly ["codemod", "codemods"], readonly ["agent-doc", "agentDocs"], readonly ["icon-set", "iconSets"]];
222
222
  export type ScannedPackage = import("./_package-scanner.mjs").ScannedPackage;
@@ -24,6 +24,7 @@ import {levenshteinDistance} from '../../../foundation/text/string-utils.mjs';
24
24
  import {AstryxError} from '../../error.mjs';
25
25
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
26
26
  import {DISCOVER_KINDS} from '../../../authoring/discover/parse.mjs';
27
+ import {compareText} from '../../../foundation/text/compare-text.mjs';
27
28
 
28
29
  /**
29
30
  * @typedef {import('../_package-scanner.mjs').ScannedPackage} ScannedPackage
@@ -131,8 +132,8 @@ export async function search(packages, query, opts) {
131
132
  a.score - b.score ||
132
133
  Number(b.item.installed) - Number(a.item.installed) ||
133
134
  KIND_ORDER.indexOf(a.item.kind) - KIND_ORDER.indexOf(b.item.kind) ||
134
- a.item.package.localeCompare(b.item.package) ||
135
- a.item.name.localeCompare(b.item.name),
135
+ compareText(a.item.package, b.item.package) ||
136
+ compareText(a.item.name, b.item.name),
136
137
  );
137
138
 
138
139
  if (ranked.length > 0) {
@@ -366,12 +366,36 @@ export function routeOwner(tree: DocsTree, entry: import("../../foundation/disco
366
366
  * Otherwise it suggests the docs the argument names in another spelling, or
367
367
  * failing that the topics and top-level namespaces, closest first and cut
368
368
  * where the matches get weaker (every one of them when none shares a word
369
- * with the argument).
369
+ * with the argument). When the argument is the name of a component, hook or
370
+ * template, the command that reads that entry comes first and takes the last
371
+ * suggestion's place, so the list keeps its length; when no suggested doc
372
+ * shares a word with the argument, that command is the only suggestion.
370
373
  * @param {unknown} topic
371
374
  * @param {DocsCatalog} catalog
375
+ * @param {{cwd?: string}} [options]
372
376
  * @returns {Promise<AstryxError>}
373
377
  */
374
- export function unknownTopicError(topic: unknown, catalog: DocsCatalog): Promise<AstryxError>;
378
+ export function unknownTopicError(topic: unknown, catalog: DocsCatalog, { cwd }?: {
379
+ cwd?: string;
380
+ }): Promise<AstryxError>;
381
+ /**
382
+ * The command that reads the component, hook or template a docs argument
383
+ * names, or null. Only an exact name counts, in any case and with or without
384
+ * spaces and hyphens; a hook also answers to its name without `use`. A
385
+ * component wins over a hook, and a hook over a template. A route never names
386
+ * one of them.
387
+ * @param {string} topic
388
+ * @param {{components?: string[], hooks?: string[], templates?: string[]}} names
389
+ * @returns {{name: string, reason: string} | null}
390
+ */
391
+ export function entryCommand(topic: string, { components, hooks, templates }: {
392
+ components?: string[];
393
+ hooks?: string[];
394
+ templates?: string[];
395
+ }): {
396
+ name: string;
397
+ reason: string;
398
+ } | null;
375
399
  /**
376
400
  * A sentence naming the packages whose docs did not load, or nothing: a doc
377
401
  * that fails to load withdraws its package's docs, so a reader who cannot
@@ -480,6 +504,7 @@ export type LinkProblem = import("../../foundation/doc-compiler/links.mjs").Link
480
504
  export type LinkResolver = import("../../foundation/doc-compiler/links.mjs").LinkResolver;
481
505
  export type DocIncluder = import("../../foundation/doc-compiler/links.mjs").DocIncluder;
482
506
  export type DocsTopicEntry = import("../../foundation/discovery/docs-discovery.mjs").DocsTopicEntry;
507
+ export type TreeInputs = Awaited<ReturnType<typeof loadTreeInputs>>;
483
508
  import { DocsCatalog } from '../../foundation/discovery/docs-discovery.mjs';
484
509
  /**
485
510
  * The catalog one integration package's docs and links read, as doctor checks
@@ -497,4 +522,5 @@ declare function packageCatalog(integration: any, discovered: {
497
522
  import { AstryxError } from '../error.mjs';
498
523
  import { OVERLAY_LANGUAGES } from '../../foundation/doc-compiler/read.mjs';
499
524
  import { overlayLanguages } from '../../foundation/doc-compiler/read.mjs';
525
+ import { loadTreeInputs } from '../../foundation/doc-compiler/tree.mjs';
500
526
  export { OVERLAY_LANGUAGES, overlayLanguages };
@@ -68,23 +68,48 @@ import {
68
68
  import {CLI_PROVIDER_ID} from '../../foundation/identity/providers.mjs';
69
69
  import {
70
70
  CORE_PACKAGE,
71
+ discoverComponentNamesWhere,
72
+ discoverIntegrationComponents,
71
73
  discoverOwnedComponents,
72
74
  discoverValidIntegrationComponents,
73
75
  } from '../../foundation/discovery/component-discovery.mjs';
74
76
  import {loadComponentDoc} from '../../foundation/discovery/component-loader.mjs';
75
77
  import {
78
+ coreFilesNaming,
79
+ foldEntryName,
80
+ integrationsFilesNaming,
81
+ } from '../../foundation/discovery/entry-name-files.mjs';
82
+ import {getAllHookNames} from '../../foundation/discovery/hook-discovery.mjs';
83
+ import {
84
+ coreTemplateIds,
76
85
  discoverCoreTemplates,
77
86
  discoverIntegrationTemplatesForOne,
87
+ integrationsMayReplaceTemplate,
88
+ listTemplates,
89
+ templateFilesNaming,
78
90
  } from '../../foundation/discovery/template-adapter.mjs';
79
- import {findCoreDir} from '../../foundation/fs/paths.mjs';
91
+ import {persistedGather} from '../../foundation/fs/gather-cache.mjs';
92
+ import {EXACT_CODEC} from '../../foundation/fs/exact-codec.mjs';
93
+ import {CLI_ROOT, findCoreDir} from '../../foundation/fs/paths.mjs';
80
94
  import {reusedWhileUnchanged} from '../../foundation/fs/read-record.mjs';
81
95
  import {AstryxError} from '../error.mjs';
82
96
  import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
83
- import {orderRouteSuggestions} from '../../foundation/text/suggest-order.mjs';
97
+ import {
98
+ carriesTypedWord,
99
+ orderRouteSuggestions,
100
+ } from '../../foundation/text/suggest-order.mjs';
84
101
  import {formatCliCommand} from '../../foundation/env/package-manager.mjs';
102
+ import {compareText} from '../../foundation/text/compare-text.mjs';
85
103
 
86
104
  export {OVERLAY_LANGUAGES, overlayLanguages};
87
105
 
106
+ /**
107
+ * The project each loaded catalog came from, so a later step of the same read
108
+ * does not load the project again.
109
+ * @type {WeakMap<DocsCatalog, Project>}
110
+ */
111
+ const projectOfCatalog = new WeakMap();
112
+
88
113
  /**
89
114
  * The project's topics: the built-in ones plus whatever the configured
90
115
  * integrations contribute.
@@ -101,7 +126,9 @@ export {OVERLAY_LANGUAGES, overlayLanguages};
101
126
  export async function loadDocsCatalog(cwd = process.cwd()) {
102
127
  try {
103
128
  const project = await Project.load(cwd);
104
- return await project.docs();
129
+ const catalog = await project.docs();
130
+ projectOfCatalog.set(catalog, project);
131
+ return catalog;
105
132
  } catch {
106
133
  return DocsCatalog.fromBuiltins();
107
134
  }
@@ -394,8 +421,32 @@ export function projectTree(catalog, {fresh = false} = {}) {
394
421
  return tree;
395
422
  }
396
423
 
397
- /** The CLI's own tree files, loaded again after one of them changes. */
398
- const cliTreeInputs = reusedWhileUnchanged(() => loadTreeInputs());
424
+ /**
425
+ * The CLI's own tree files, kept between runs and loaded again after one of
426
+ * them changes. They are the same for every project this copy of the CLI
427
+ * runs in, so the copy's folder is the whole key.
428
+ */
429
+ const keptTreeInputs = reusedWhileUnchanged(() =>
430
+ persistedGather(['docs-tree-inputs', CLI_ROOT], loadTreeInputs, TREE_INPUTS),
431
+ );
432
+
433
+ /**
434
+ * The CLI's own tree files, read from the files themselves, never from the
435
+ * kept copy: doctor checks what the files say.
436
+ */
437
+ const readTreeInputs = reusedWhileUnchanged(() => loadTreeInputs());
438
+
439
+ /** @typedef {Awaited<ReturnType<typeof loadTreeInputs>>} TreeInputs */
440
+
441
+ /** The tree inputs, kept exactly, with the shape they need. */
442
+ const TREE_INPUTS = {
443
+ ...EXACT_CODEC,
444
+ valid: (/** @type {any} */ value) =>
445
+ value != null &&
446
+ Array.isArray(value.namespaces) &&
447
+ Array.isArray(value.docs) &&
448
+ Array.isArray(value.diagnostics),
449
+ };
399
450
 
400
451
  /**
401
452
  * Every flat topic in the catalog, as the tree's topic levels read it.
@@ -442,7 +493,7 @@ async function flatTopicInputs(catalog) {
442
493
  */
443
494
  async function buildProjectTree(catalog, fresh) {
444
495
  const added = catalog.treeInputs;
445
- const cli = await cliTreeInputs({fresh});
496
+ const cli = fresh ? await readTreeInputs({fresh}) : await keptTreeInputs();
446
497
  const result = buildDocsTree({
447
498
  namespaces: [...cli.namespaces, ...added.flatMap(each => each.namespaces)],
448
499
  docs: [...cli.docs, ...added.flatMap(each => each.guides)],
@@ -1932,12 +1983,16 @@ function movedRoute(topic, tree) {
1932
1983
  * Otherwise it suggests the docs the argument names in another spelling, or
1933
1984
  * failing that the topics and top-level namespaces, closest first and cut
1934
1985
  * where the matches get weaker (every one of them when none shares a word
1935
- * with the argument).
1986
+ * with the argument). When the argument is the name of a component, hook or
1987
+ * template, the command that reads that entry comes first and takes the last
1988
+ * suggestion's place, so the list keeps its length; when no suggested doc
1989
+ * shares a word with the argument, that command is the only suggestion.
1936
1990
  * @param {unknown} topic
1937
1991
  * @param {DocsCatalog} catalog
1992
+ * @param {{cwd?: string}} [options]
1938
1993
  * @returns {Promise<AstryxError>}
1939
1994
  */
1940
- export async function unknownTopicError(topic, catalog) {
1995
+ export async function unknownTopicError(topic, catalog, {cwd} = {}) {
1941
1996
  const tree = await projectTree(catalog);
1942
1997
  /** @type {Array<{name: string, reason: string}>} */
1943
1998
  let suggestions = [];
@@ -1975,7 +2030,10 @@ export async function unknownTopicError(topic, catalog) {
1975
2030
  )
1976
2031
  .map(node => ({name: node.route, reason: node.summary}));
1977
2032
  }
2033
+ // Every topic and namespace: the list a name no doc shares a word with gets.
2034
+ let everyDoc = false;
1978
2035
  if (suggestions.length === 0) {
2036
+ everyDoc = true;
1979
2037
  suggestions = [
1980
2038
  ...tree
1981
2039
  .roots()
@@ -2001,6 +2059,16 @@ export async function unknownTopicError(topic, catalog) {
2001
2059
  ERROR_CODES.ERR_UNKNOWN_TOPIC,
2002
2060
  );
2003
2061
  }
2062
+ const elsewhere =
2063
+ suggestions.length > 0 ? await entryElsewhere(topic, catalog, cwd) : null;
2064
+ if (elsewhere) {
2065
+ const sharesAWord =
2066
+ !everyDoc ||
2067
+ suggestions.some(entry => carriesTypedWord(String(topic), entry.name));
2068
+ suggestions = sharesAWord
2069
+ ? [elsewhere, ...suggestions.slice(0, -1)]
2070
+ : [elsewhere];
2071
+ }
2004
2072
  return new AstryxError(
2005
2073
  `Unknown topic "${String(topic)}"${notLoaded(catalog)}`,
2006
2074
  suggestions,
@@ -2008,6 +2076,177 @@ export async function unknownTopicError(topic, catalog) {
2008
2076
  );
2009
2077
  }
2010
2078
 
2079
+ /**
2080
+ * The command that reads the component, hook or template a docs argument
2081
+ * names, or null. Only an exact name counts, in any case and with or without
2082
+ * spaces and hyphens; a hook also answers to its name without `use`. A
2083
+ * component wins over a hook, and a hook over a template. A route never names
2084
+ * one of them.
2085
+ * @param {string} topic
2086
+ * @param {{components?: string[], hooks?: string[], templates?: string[]}} names
2087
+ * @returns {{name: string, reason: string} | null}
2088
+ */
2089
+ export function entryCommand(
2090
+ topic,
2091
+ {components = [], hooks = [], templates = []},
2092
+ ) {
2093
+ if (topic.includes('/')) return null;
2094
+ const wanted = foldEntryName(topic);
2095
+ if (wanted === '') return null;
2096
+ const component = components.find(name => foldEntryName(name) === wanted);
2097
+ if (component) {
2098
+ return {
2099
+ name: `astryx component ${component}`,
2100
+ reason: 'a component, not a docs topic',
2101
+ };
2102
+ }
2103
+ const hook = hooks.find(name => {
2104
+ const folded = foldEntryName(name);
2105
+ return folded === wanted || folded === `use${wanted}`;
2106
+ });
2107
+ if (hook) {
2108
+ return {name: `astryx hook ${hook}`, reason: 'a hook, not a docs topic'};
2109
+ }
2110
+ const template = templates.find(name => foldEntryName(name) === wanted);
2111
+ if (template) {
2112
+ return {
2113
+ name: `astryx template ${template}`,
2114
+ reason: 'a template, not a docs topic',
2115
+ };
2116
+ }
2117
+ return null;
2118
+ }
2119
+
2120
+ /**
2121
+ * {@link entryCommand} over the names the project's catalogs hold. File names
2122
+ * and doc text say first which catalogs can hold the argument; a catalog is
2123
+ * asked only then, only for the names that fold to the argument, and only
2124
+ * when the one before it has no match. So a name no file carries reads no doc.
2125
+ * A check that fails gives no hint.
2126
+ * @param {unknown} topic
2127
+ * @param {DocsCatalog} catalog the catalog the read used; its project is
2128
+ * reused
2129
+ * @param {string} [cwd]
2130
+ * @returns {Promise<{name: string, reason: string} | null>}
2131
+ */
2132
+ async function entryElsewhere(topic, catalog, cwd = process.cwd()) {
2133
+ if (typeof topic !== 'string' || topic.includes('/')) return null;
2134
+ const wanted = foldEntryName(topic);
2135
+ if (wanted === '') return null;
2136
+ let project = projectOfCatalog.get(catalog);
2137
+ try {
2138
+ project ??= await Project.load(cwd);
2139
+ } catch {
2140
+ return null;
2141
+ }
2142
+ const coreDir = project.coreDir();
2143
+ const integrations = project.loadedIntegrations;
2144
+ /** @param {string} name */
2145
+ const isWanted = name => foldEntryName(name) === wanted;
2146
+ /** @param {string} name */
2147
+ const isWantedHook = name =>
2148
+ isWanted(name) || foldEntryName(name) === `use${wanted}`;
2149
+ /** @type {{component: boolean, hook: boolean, componentTops?: Set<string>, hookTops?: Set<string>}} */
2150
+ let inCore = {component: false, hook: false};
2151
+ try {
2152
+ if (coreDir) inCore = coreFilesNaming(coreDir, wanted);
2153
+ } catch {
2154
+ inCore = {component: true, hook: true};
2155
+ }
2156
+ /** @type {Array<() => Promise<{components?: string[], hooks?: string[], templates?: string[]}>>} */
2157
+ const catalogs = [
2158
+ async () => ({
2159
+ components:
2160
+ coreDir && inCore.component
2161
+ ? discoverComponentNamesWhere(coreDir, isWanted, inCore.componentTops)
2162
+ : [],
2163
+ }),
2164
+ async () => ({
2165
+ components: await integrationComponentNames(
2166
+ integrations,
2167
+ wanted,
2168
+ isWanted,
2169
+ ),
2170
+ }),
2171
+ async () => ({
2172
+ hooks:
2173
+ coreDir && inCore.hook
2174
+ ? getAllHookNames(coreDir, isWantedHook, inCore.hookTops)
2175
+ : [],
2176
+ }),
2177
+ async () => ({
2178
+ templates: await templateNames(project, integrations, wanted),
2179
+ }),
2180
+ ];
2181
+ for (const load of catalogs) {
2182
+ let names;
2183
+ try {
2184
+ names = await load();
2185
+ } catch {
2186
+ continue;
2187
+ }
2188
+ const found = entryCommand(topic, names);
2189
+ if (found) return found;
2190
+ }
2191
+ return null;
2192
+ }
2193
+
2194
+ /**
2195
+ * The names `isWanted` accepts among the valid components of the loaded
2196
+ * integrations, in project order. Only an integration whose files can carry
2197
+ * the name is read, and it loads its docs only when it lists such a name.
2198
+ * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} integrations
2199
+ * @param {string} wanted the folded name
2200
+ * @param {(name: string) => boolean} isWanted
2201
+ * @returns {Promise<string[]>}
2202
+ */
2203
+ async function integrationComponentNames(integrations, wanted, isWanted) {
2204
+ const naming = integrationsFilesNaming(
2205
+ integrations.map(integration => integration.components),
2206
+ wanted,
2207
+ );
2208
+ for (const [at, integration] of integrations.entries()) {
2209
+ if (!naming[at]) continue;
2210
+ if (!discoverIntegrationComponents(integration).some(r => isWanted(r.name)))
2211
+ continue;
2212
+ const {components} = await discoverValidIntegrationComponents(integration);
2213
+ const names = components.map(r => r.name).filter(isWanted);
2214
+ if (names.length > 0) return names;
2215
+ }
2216
+ return [];
2217
+ }
2218
+
2219
+ /**
2220
+ * The template ids that fold to `wanted`, as the project's template list
2221
+ * holds them. Core's ids come from file names. The whole list loads only when
2222
+ * an integration ships a template doc with such an id, when more than one
2223
+ * Core id folds to it (the list decides their order), or when one does and
2224
+ * an integration template may replace it.
2225
+ * @param {Project} project
2226
+ * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} integrations
2227
+ * @param {string} wanted the folded name
2228
+ * @returns {Promise<string[]>}
2229
+ */
2230
+ async function templateNames(project, integrations, wanted) {
2231
+ /** @param {string} name */
2232
+ const isWanted = name => foldEntryName(name) === wanted;
2233
+ const {blocks, listed} = templateFilesNaming(integrations, wanted);
2234
+ const core = blocks
2235
+ ? coreTemplateIds(isWanted)
2236
+ : listTemplates().filter(isWanted);
2237
+ if (
2238
+ !listed &&
2239
+ core.length < 2 &&
2240
+ (core.length === 0 || !integrationsMayReplaceTemplate(integrations))
2241
+ ) {
2242
+ return core;
2243
+ }
2244
+ return /** @type {Array<{dirName?: unknown}>} */ (await project.templates())
2245
+ .map(record => record.dirName)
2246
+ .filter(name => typeof name === 'string')
2247
+ .filter(isWanted);
2248
+ }
2249
+
2011
2250
  /**
2012
2251
  * A sentence naming the packages whose docs did not load, or nothing: a doc
2013
2252
  * that fails to load withdraws its package's docs, so a reader who cannot
@@ -2041,7 +2280,7 @@ export async function resolveTopicDocs(topic, options = {}, loaded) {
2041
2280
  undefined,
2042
2281
  ERROR_CODES.ERR_UNKNOWN_TOPIC,
2043
2282
  )
2044
- : await unknownTopicError(topic, found.catalog);
2283
+ : await unknownTopicError(topic, found.catalog, {cwd});
2045
2284
  }
2046
2285
  const {catalog, entry} = found;
2047
2286
  const node = await lowerTopic(catalog, entry, effectiveLang);
@@ -2081,6 +2320,6 @@ export async function integrationDocTypes(integration, cwd) {
2081
2320
  unchecked: [
2082
2321
  ...report.unchecked,
2083
2322
  ...unread.map(entry => ({doc: rel(entry.path), reason: entry.reason})),
2084
- ].sort((a, b) => a.doc.localeCompare(b.doc)),
2323
+ ].sort((a, b) => compareText(a.doc, b.doc)),
2085
2324
  };
2086
2325
  }