@astryxdesign/cli 0.7.2 → 0.7.3-canary.02f5fe4

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 (373) hide show
  1. package/README.md +104 -71
  2. package/api/build/_adapter.d.mts +58 -0
  3. package/api/build/_adapter.mjs +127 -3
  4. package/api/build/blocks/blocks.d.mts +92 -0
  5. package/api/build/blocks/blocks.mjs +528 -0
  6. package/api/build/blocks/blocks.test.mjs +238 -0
  7. package/api/build/blocks/blocks.weights.json +1 -0
  8. package/api/build/build.mjs +25 -6
  9. package/api/build/build.type.mjs +1 -1
  10. package/api/build/kit/answer.d.mts +18 -0
  11. package/api/build/kit/answer.mjs +195 -0
  12. package/api/build/kit/answer.test.mjs +108 -0
  13. package/api/build/kit/kind.d.mts +25 -0
  14. package/api/build/kit/kind.mjs +170 -0
  15. package/api/build/kit/kit.d.mts +2 -4
  16. package/api/build/kit/kit.mjs +8 -398
  17. package/api/build/kit/rank.d.mts +3 -32
  18. package/api/build/kit/rank.mjs +25 -342
  19. package/api/build/kit/rank.test.mjs +2 -1
  20. package/api/build/kit/signals.d.mts +79 -0
  21. package/api/build/kit/signals.mjs +295 -0
  22. package/api/build/kit/start.d.mts +32 -0
  23. package/api/build/kit/start.mjs +163 -0
  24. package/api/build/kit/words.d.mts +72 -0
  25. package/api/build/kit/words.mjs +202 -0
  26. package/api/build/tree.d.mts +20 -0
  27. package/api/build/tree.mjs +53 -0
  28. package/api/build/tree.test.mjs +185 -0
  29. package/api/build/tree.weights.json +1 -0
  30. package/api/component/_adapter.mjs +39 -5
  31. package/api/component/component-replacement.test.mjs +1 -0
  32. package/api/component/component.mjs +17 -3
  33. package/api/component/component.test.mjs +15 -0
  34. package/api/component/doc-links.test.mjs +2 -2
  35. package/api/discover/_adapter.d.mts +1 -2
  36. package/api/discover/_adapter.mjs +42 -17
  37. package/api/discover/_adapter.test.mjs +42 -0
  38. package/api/discover/discover.mjs +0 -1
  39. package/api/docs/_adapter.d.mts +2 -2
  40. package/api/docs/_adapter.mjs +82 -23
  41. package/api/docs/docs-homes.test.mjs +127 -0
  42. package/api/docs/docs.doc.mjs +3 -3
  43. package/api/docs/docs.test.mjs +35 -19
  44. package/api/docs/integration-tree.test.mjs +20 -20
  45. package/api/docs/integrationDocs.test.mjs +1 -1
  46. package/api/docs/namespace-section.test.mjs +6 -6
  47. package/api/docs/reference-blocks.test.mjs +2 -2
  48. package/api/doctor/_adapter.d.mts +33 -13
  49. package/api/doctor/_adapter.mjs +55 -25
  50. package/api/doctor/doctor.d.mts +23 -5
  51. package/api/doctor/doctor.mjs +183 -40
  52. package/api/doctor/doctor.test.mjs +95 -12
  53. package/api/hook/hook.mjs +1 -1
  54. package/api/init/init.doc.mjs +20 -6
  55. package/api/init/init.test.mjs +18 -2
  56. package/api/init/init.type.d.mts +3 -3
  57. package/api/init/init.type.mjs +3 -3
  58. package/api/init/remove/remove.mjs +17 -4
  59. package/api/init/remove/remove.test.mjs +114 -2
  60. package/api/init/run/run.mjs +69 -6
  61. package/api/integration/_adapter.d.mts +8 -0
  62. package/api/integration/_adapter.mjs +21 -1
  63. package/api/integration/authoring-checks.mjs +83 -9
  64. package/api/integration/authoring-checks.test.mjs +220 -0
  65. package/api/integration/pack-check.mjs +123 -4
  66. package/api/integration/pack-check.test.mjs +87 -0
  67. package/api/integration/validate-integration-case-disk.test.mjs +111 -0
  68. package/api/integration/validate-integration-fixes.test.mjs +6 -5
  69. package/api/integration/validate-integration-gaps.test.mjs +1975 -0
  70. package/api/integration/validate-integration.d.mts +15 -2
  71. package/api/integration/validate-integration.mjs +298 -39
  72. package/api/integration/validate-integration.type.d.mts +90 -1
  73. package/api/integration/validate-integration.type.mjs +67 -2
  74. package/api/integration/validateIntegration.doc.mjs +1 -1
  75. package/api/search/ORDERING.md +28 -0
  76. package/api/search/_adapter.d.mts +82 -2
  77. package/api/search/_adapter.mjs +157 -10
  78. package/api/search/_adapter.test.mjs +173 -0
  79. package/api/search/_candidate-score.d.mts +40 -0
  80. package/api/search/_candidate-score.mjs +238 -0
  81. package/api/search/_cards.json +6098 -0
  82. package/api/search/_compound.d.mts +50 -0
  83. package/api/search/_compound.mjs +170 -0
  84. package/api/search/_doc-searcher.d.mts +4 -0
  85. package/api/search/_doc-searcher.mjs +23 -0
  86. package/api/search/_doc-searcher.test.mjs +36 -0
  87. package/api/search/_doc-searcher.weights.json +1 -0
  88. package/api/search/_doc-text.d.mts +30 -0
  89. package/api/search/_doc-text.mjs +87 -0
  90. package/api/search/_entries.d.mts +63 -0
  91. package/api/search/_entries.mjs +232 -0
  92. package/api/search/_entries.test.mjs +48 -0
  93. package/api/search/_features.d.mts +35 -0
  94. package/api/search/_features.mjs +155 -0
  95. package/api/search/_gather-components.d.mts +26 -0
  96. package/api/search/_gather-components.mjs +284 -0
  97. package/api/search/_gather-docs.d.mts +20 -0
  98. package/api/search/_gather-docs.mjs +254 -0
  99. package/api/search/_gather-hooks.d.mts +12 -0
  100. package/api/search/_gather-hooks.mjs +52 -0
  101. package/api/search/_gather-templates.d.mts +25 -0
  102. package/api/search/_gather-templates.mjs +107 -0
  103. package/api/search/_lexical.d.mts +135 -0
  104. package/api/search/_lexical.mjs +351 -0
  105. package/api/search/_main-searcher.d.mts +19 -0
  106. package/api/search/_main-searcher.mjs +115 -0
  107. package/api/search/_main-searcher.test.mjs +106 -0
  108. package/api/search/_main-searcher.weights.json +1 -0
  109. package/api/search/_module-doc.d.mts +32 -0
  110. package/api/search/_module-doc.mjs +78 -0
  111. package/api/search/_order.d.mts +32 -0
  112. package/api/search/_order.mjs +162 -0
  113. package/api/search/_order.test.mjs +72 -0
  114. package/api/search/_priority.d.mts +50 -0
  115. package/api/search/_priority.mjs +139 -0
  116. package/api/search/_query-words.d.mts +25 -0
  117. package/api/search/_query-words.mjs +92 -0
  118. package/api/search/_query.d.mts +65 -0
  119. package/api/search/_query.mjs +176 -0
  120. package/api/search/_result.d.mts +97 -0
  121. package/api/search/_result.mjs +150 -0
  122. package/api/search/_score.d.mts +60 -0
  123. package/api/search/_score.mjs +283 -0
  124. package/api/search/_synonyms.d.mts +21 -0
  125. package/api/search/_synonyms.mjs +67 -0
  126. package/api/search/_template-searcher.d.mts +4 -0
  127. package/api/search/_template-searcher.mjs +23 -0
  128. package/api/search/_template-searcher.test.mjs +40 -0
  129. package/api/search/_template-searcher.weights.json +1 -0
  130. package/api/search/_titles.d.mts +33 -0
  131. package/api/search/_titles.mjs +65 -0
  132. package/api/search/_words.d.mts +64 -0
  133. package/api/search/_words.mjs +157 -0
  134. package/api/search/search.d.mts +22 -305
  135. package/api/search/search.doc.mjs +8 -6
  136. package/api/search/search.mjs +56 -2482
  137. package/api/search/search.test.mjs +14 -14
  138. package/api/search/search.type.d.mts +6 -1
  139. package/api/search/search.type.mjs +6 -1
  140. package/api/search/tree.d.mts +15 -0
  141. package/api/search/tree.mjs +40 -0
  142. package/api/search/tree.test.mjs +66 -0
  143. package/api/search/tree.weights.json +1 -0
  144. package/api/template/template.mjs +5 -1
  145. package/api/theme/build/build.packed-old-core.test.mjs +1 -0
  146. package/api/upgrade/_adapter.d.mts +57 -9
  147. package/api/upgrade/_adapter.mjs +198 -28
  148. package/api/upgrade/registry/registry.d.mts +10 -4
  149. package/api/upgrade/registry/registry.mjs +33 -16
  150. package/api/upgrade/registry/registry.test.mjs +85 -0
  151. package/api/upgrade/run/run.d.mts +4 -2
  152. package/api/upgrade/run/run.mjs +13 -2
  153. package/api/upgrade/run/run.test.mjs +417 -3
  154. package/api/upgrade/upgrade.doc.mjs +10 -5
  155. package/api/upgrade/upgrade.mjs +13 -2
  156. package/api/upgrade/upgrade.test.mjs +194 -0
  157. package/api/upgrade/upgrade.type.d.mts +5 -3
  158. package/api/upgrade/upgrade.type.mjs +8 -6
  159. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +11 -0
  160. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +3 -3
  161. package/assets/docs/author-a-theme.doc.mjs +2 -2
  162. package/assets/docs/is-my-code-good.doc.mjs +287 -0
  163. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  164. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  165. package/assets/docs/tree/add-a-topic.doc.mjs +2 -2
  166. package/assets/docs/tree/agent-guidance.doc.mjs +1 -1
  167. package/assets/docs/tree/api.doc.mjs +6 -0
  168. package/assets/docs/tree/{integrations.doc.mjs → authoring.doc.mjs} +15 -6
  169. package/assets/docs/tree/block-template.doc.mjs +1 -1
  170. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  171. package/assets/docs/tree/building-blocks.doc.mjs +2 -2
  172. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  173. package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
  174. package/assets/docs/tree/checks.doc.mjs +3 -3
  175. package/assets/docs/tree/ci-and-containers.doc.mjs +13 -0
  176. package/assets/docs/tree/cli-command.doc.mjs +1 -1
  177. package/assets/docs/tree/cli.doc.mjs +1 -1
  178. package/assets/docs/tree/codemods.doc.mjs +1 -1
  179. package/assets/docs/tree/component-family.doc.mjs +1 -1
  180. package/assets/docs/tree/component-imports.doc.mjs +1 -1
  181. package/assets/docs/tree/components.doc.mjs +1 -1
  182. package/assets/docs/tree/configuration.doc.mjs +1 -1
  183. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +1 -1
  184. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  185. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  186. package/assets/docs/tree/docs.doc.mjs +1 -1
  187. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  188. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  189. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  190. package/assets/docs/tree/extend-or-replace.doc.mjs +1 -1
  191. package/assets/docs/{authoring.doc.mjs → tree/field-reference.doc.mjs} +4 -3
  192. package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
  193. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  194. package/assets/docs/tree/global-integrations.doc.mjs +2 -2
  195. package/assets/docs/tree/grade-template-with-agent.doc.mjs +4 -4
  196. package/assets/docs/tree/help.doc.mjs +2 -2
  197. package/assets/docs/tree/host-entry.doc.mjs +128 -0
  198. package/assets/docs/tree/links.doc.mjs +1 -1
  199. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  200. package/assets/docs/tree/page-template.doc.mjs +1 -1
  201. package/assets/docs/tree/publishing.doc.mjs +1 -1
  202. package/assets/docs/tree/quick-start.doc.mjs +1 -1
  203. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  204. package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
  205. package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
  206. package/assets/docs/tree/see-it-in-an-app.doc.mjs +1 -1
  207. package/assets/docs/tree/ship.doc.mjs +2 -2
  208. package/assets/docs/tree/short-and-findable.doc.mjs +1 -1
  209. package/assets/docs/tree/single-component.doc.mjs +1 -1
  210. package/assets/docs/tree/start-a-template.doc.mjs +1 -1
  211. package/assets/docs/tree/subcomponent.doc.mjs +1 -1
  212. package/assets/docs/tree/template-assets.doc.mjs +1 -1
  213. package/assets/docs/tree/template-doc-overview.doc.mjs +2 -2
  214. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  215. package/assets/docs/tree/template-grading-rubric.doc.mjs +17 -38
  216. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  217. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  218. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  219. package/assets/docs/tree/templates.doc.mjs +1 -1
  220. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  221. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  222. package/assets/docs/tree/themes.doc.mjs +1 -1
  223. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  224. package/assets/docs/tree/troubleshooting.doc.mjs +1 -1
  225. package/assets/docs/tree/upgrading.doc.mjs +1 -1
  226. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  227. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  228. package/assets/docs/tree/versioning.doc.mjs +5 -1
  229. package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
  230. package/assets/docs/tree/write-the-template-file.doc.mjs +1 -1
  231. package/assets/docs/use-integrations.doc.mjs +120 -0
  232. package/assets/docs/working-with-ai.doc.mjs +6 -2
  233. package/assets/templates/themes/butter/butterTheme.ts +4 -2
  234. package/assets/templates/themes/stone/stoneTheme.ts +4 -2
  235. package/assets/templates/themes/y2k/y2kTheme.ts +4 -2
  236. package/authoring/debug/parse.d.mts +1 -1
  237. package/authoring/doctypes/schema/schema.doc.mjs +1 -1
  238. package/authoring/integration/integration.doc.mjs +1 -1
  239. package/authoring/integration/type.ts +1 -1
  240. package/clients/cli/bin/astryx.mjs +7 -78
  241. package/clients/cli/command-result-coverage.test.mjs +6 -5
  242. package/clients/cli/commands/build-theme.color-scheme.test.mjs +1 -1
  243. package/clients/cli/commands/{component/index.mjs → component.mjs} +37 -37
  244. package/clients/cli/commands/component.test.mjs +6 -6
  245. package/clients/cli/commands/docs.doc.mjs +2 -2
  246. package/clients/cli/commands/docs.mjs +1 -1
  247. package/clients/cli/commands/docs.test.mjs +14 -14
  248. package/clients/cli/commands/doctor-integration.test.mjs +49 -1
  249. package/clients/cli/commands/doctor.doc.mjs +1 -1
  250. package/clients/cli/commands/doctor.mjs +40 -0
  251. package/clients/cli/commands/doctor.test.mjs +65 -0
  252. package/clients/cli/commands/{hook/index.mjs → hook.mjs} +22 -22
  253. package/clients/cli/commands/import-hint-correctness.test.mjs +1 -1
  254. package/clients/cli/commands/init.behavior.test.mjs +230 -1
  255. package/clients/cli/commands/init.doc.mjs +28 -9
  256. package/clients/cli/commands/init.flag-help.test.mjs +1 -0
  257. package/clients/cli/commands/init.mjs +2 -2
  258. package/clients/cli/commands/integration-check.test.mjs +48 -0
  259. package/clients/cli/commands/integration.doc.mjs +1 -1
  260. package/clients/cli/commands/manifest.doc.mjs +1 -1
  261. package/clients/cli/commands/manifest.mjs +67 -0
  262. package/clients/cli/commands/outside-project.test.mjs +101 -1
  263. package/clients/cli/commands/postinstall.doc.mjs +23 -0
  264. package/clients/cli/commands/postinstall.mjs +31 -0
  265. package/clients/cli/commands/setup-nudge.test.mjs +78 -0
  266. package/clients/cli/commands/{build-theme.mjs → theme.mjs} +1 -1
  267. package/clients/cli/commands/upgrade.doc.mjs +4 -2
  268. package/clients/cli/commands/upgrade.mjs +9 -2
  269. package/clients/cli/commands/upgrade.subfolder-path.test.mjs +97 -0
  270. package/clients/cli/index.mjs +54 -94
  271. package/clients/cli/lib/component-format.mjs +1 -1
  272. package/clients/cli/lib/define-command.mjs +12 -7
  273. package/clients/cli/lib/exit-codes.test.mjs +5 -0
  274. package/clients/cli/lib/manifest.test.mjs +12 -0
  275. package/clients/cli/lib/welcome-box.mjs +50 -0
  276. package/clients/cli/run.mjs +108 -0
  277. package/foundation/agent-docs/agent-doc-state.d.mts +32 -7
  278. package/foundation/agent-docs/agent-doc-state.mjs +58 -9
  279. package/foundation/agent-docs/agent-docs.d.mts +100 -12
  280. package/foundation/agent-docs/agent-docs.mjs +1017 -105
  281. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +1239 -17
  282. package/foundation/agent-docs/agent-docs.test.mjs +683 -39
  283. package/foundation/agent-docs/computer-agent-text.d.mts +39 -2
  284. package/foundation/agent-docs/computer-agent-text.mjs +135 -8
  285. package/foundation/agent-docs/computer-agent-text.test.mjs +99 -2
  286. package/foundation/config/project.mjs +20 -22
  287. package/foundation/config/project.test.mjs +56 -0
  288. package/foundation/discovery/authoring-self-docs.d.mts +7 -0
  289. package/foundation/discovery/authoring-self-docs.mjs +16 -4
  290. package/foundation/discovery/authoring-self-docs.test.mjs +15 -3
  291. package/foundation/discovery/authoring-surface.d.mts +1 -1
  292. package/foundation/discovery/authoring-surface.mjs +2 -2
  293. package/foundation/discovery/authoring-surface.test.mjs +1 -1
  294. package/foundation/discovery/cli-self-docs.d.mts +2 -1
  295. package/foundation/discovery/cli-self-docs.mjs +4 -3
  296. package/foundation/discovery/cli-self-docs.test.mjs +2 -2
  297. package/foundation/discovery/component-discovery.d.mts +37 -0
  298. package/foundation/discovery/component-discovery.mjs +80 -5
  299. package/foundation/discovery/component-loader.d.mts +1 -1
  300. package/foundation/discovery/docs-discovery.mjs +14 -1
  301. package/foundation/discovery/module-exports.d.mts +41 -0
  302. package/foundation/discovery/module-exports.mjs +253 -0
  303. package/foundation/discovery/runner-allowlist.d.mts +2 -4
  304. package/foundation/discovery/runner-allowlist.mjs +2 -4
  305. package/foundation/discovery/runner-commands.d.mts +77 -0
  306. package/foundation/discovery/runner-commands.mjs +294 -0
  307. package/foundation/discovery/runner-commands.test.mjs +128 -0
  308. package/foundation/discovery/stray-pointers.test.mjs +1 -1
  309. package/foundation/discovery/template-adapter.mjs +18 -1
  310. package/foundation/discovery/template-needs.mjs +1 -44
  311. package/foundation/discovery/theme-discovery.mjs +147 -3
  312. package/foundation/doc-compiler/doc-loads.test.mjs +33 -9
  313. package/foundation/doc-compiler/read.mjs +59 -1
  314. package/foundation/doc-compiler/read.test.mjs +11 -2
  315. package/foundation/doc-compiler/split-topic-keywords.test.mjs +3 -2
  316. package/foundation/doc-compiler/tree.d.mts +32 -6
  317. package/foundation/doc-compiler/tree.mjs +77 -43
  318. package/foundation/doc-compiler/tree.test.mjs +7 -7
  319. package/foundation/fs/paths.d.mts +70 -8
  320. package/foundation/fs/paths.mjs +556 -38
  321. package/foundation/fs/paths.test.mjs +430 -54
  322. package/foundation/fs/read-record.d.mts +18 -0
  323. package/foundation/fs/read-record.mjs +131 -0
  324. package/foundation/fs/read-record.test.mjs +77 -0
  325. package/foundation/integrations/autolink.d.mts +2 -1
  326. package/foundation/integrations/autolink.mjs +4 -13
  327. package/foundation/integrations/cli-peer-version.d.mts +36 -0
  328. package/foundation/integrations/cli-peer-version.mjs +132 -0
  329. package/foundation/integrations/cli-peer-version.test.mjs +354 -0
  330. package/foundation/integrations/computer-integrations.d.mts +6 -3
  331. package/foundation/integrations/computer-integrations.mjs +38 -9
  332. package/foundation/integrations/contribution-inventory.d.mts +15 -20
  333. package/foundation/integrations/contribution-inventory.mjs +41 -5
  334. package/foundation/integrations/exports-subpaths.d.mts +57 -0
  335. package/foundation/integrations/exports-subpaths.mjs +113 -0
  336. package/foundation/integrations/integrations.d.mts +27 -1
  337. package/foundation/integrations/integrations.mjs +61 -2
  338. package/foundation/integrations/public-imports.d.mts +118 -0
  339. package/foundation/integrations/public-imports.mjs +1769 -0
  340. package/foundation/integrations/public-imports.test.mjs +1793 -0
  341. package/foundation/integrations/validate-contributions.d.mts +115 -0
  342. package/foundation/integrations/validate-contributions.mjs +1168 -13
  343. package/foundation/release/cache.test.mjs +24 -21
  344. package/foundation/release/global-state.d.mts +8 -4
  345. package/foundation/release/global-state.mjs +4 -2
  346. package/foundation/release/handoff.d.mts +23 -4
  347. package/foundation/release/handoff.mjs +175 -8
  348. package/foundation/release/notices.d.mts +62 -8
  349. package/foundation/release/notices.mjs +136 -25
  350. package/foundation/release/notices.test.mjs +21 -0
  351. package/foundation/release/run-context.mjs +14 -0
  352. package/foundation/response/response-types.doc.mjs +1 -1
  353. package/foundation/route/route.d.mts +285 -0
  354. package/foundation/route/route.mjs +324 -0
  355. package/foundation/route/route.test.mjs +153 -0
  356. package/foundation/runtime/hosted-runtime.test.mjs +403 -0
  357. package/foundation/runtime/locked-versions.d.mts +32 -0
  358. package/foundation/runtime/locked-versions.mjs +65 -0
  359. package/foundation/runtime/package-root.d.mts +91 -0
  360. package/foundation/runtime/package-root.mjs +174 -0
  361. package/foundation/runtime/package-set.d.mts +62 -0
  362. package/foundation/runtime/package-set.mjs +130 -0
  363. package/foundation/runtime/package-set.test.mjs +432 -0
  364. package/foundation/text/string-utils.d.mts +2 -1
  365. package/foundation/text/string-utils.mjs +16 -5
  366. package/foundation/text/suggest-order.d.mts +72 -0
  367. package/foundation/text/suggest-order.mjs +363 -0
  368. package/foundation/text/suggest-order.test.mjs +259 -0
  369. package/host/door-conformance.test.mjs +274 -0
  370. package/host/index.d.ts +116 -0
  371. package/host/index.mjs +295 -0
  372. package/host/index.test.mjs +302 -0
  373. package/package.json +14 -9
@@ -18,6 +18,7 @@
18
18
  * @property {string} [codemods]
19
19
  * @property {string} [docs]
20
20
  * @property {string} [issuesUrl]
21
+ * @property {string[]} [__declaredKeys]
21
22
  * @property {string[]} [__unknownKeys]
22
23
  * @property {string} __spec
23
24
  * @property {string} __packageDir
@@ -38,9 +39,23 @@
38
39
  * "healthy" — the two are otherwise byte-identical.
39
40
  * @typedef {object} ValidateIntegrationResponse
40
41
  * @property {'integration.validate'} type
41
- * @property {{validated: boolean, name: string | null, version: string | null, issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[], notes?: Array<{code: string, message: string}>, docTypes?: DocTypesReport}} data
42
+ * @property {{validated: boolean, name: string | null, version: string | null, issues: import('../../foundation/integrations/issue').AstryxIntegrationIssue[], notes?: Array<{code: string, message: string}>, docTypes?: DocTypesReport, docNames?: DocNamesReport, blockComponents?: BlockComponentsReport, publicImports?: PublicImportsReport}} data
42
43
  * `notes`: information beside the issues that fails nothing, such as
43
- * `invalid_cli_command`, a `cliCommand` that was ignored as malformed
44
+ * `invalid_cli_command`, a `cliCommand` that was ignored as malformed;
45
+ * `cli_peer_version`, the running CLI outside the package's
46
+ * `@astryxdesign/cli` peer range; and
47
+ * the package layout findings added after the last minor release, each with
48
+ * its fix in the message: two docs for one component
49
+ * (`duplicate_component_doc`), a root reached through a symlink
50
+ * (`symlinked_root`), a contribution file that cannot be read
51
+ * (`unreadable_file`), a package.json without `name` or `version`
52
+ * (`invalid_package_json`), no provider ID (`no_provider_id`), and a doc
53
+ * whose file name differs from its source only in letter case where the two
54
+ * still pair (`source_without_component_doc`); `doc_name_mismatch` and
55
+ * `unknown_block_component` (see `docNames` and `blockComponents`); and
56
+ * since 0.7.3 each public-import finding; they become warnings in the next
57
+ * minor release; and `runner_command`, an Astryx command a topic writes
58
+ * with a package runner
44
59
  */
45
60
 
46
61
  /**
@@ -54,4 +69,54 @@
54
69
  * components or docs root, which those readers skip) were not checked
55
70
  */
56
71
 
72
+ /**
73
+ * Each component doc whose `name` differs from the name it is listed under,
74
+ * judged against its source. Present when the manifest loads. A name the
75
+ * module its printed import names provably does not export is a
76
+ * `doc_name_mismatch` note beside the issues, with its fix in the message
77
+ * (it becomes a warning in the next minor release), so `findings` is always
78
+ * empty; `unchecked` lists each doc whose source's
79
+ * exports could not all be read (a re-export from another package, `export
80
+ * =`, a destructured binding, a namespace): `file` (the doc, package-relative),
81
+ * `name` (what the doc says), and `reason`.
82
+ *
83
+ * @typedef {{status: 'checked', findings: [], unchecked: Array<{file: string, name: string, reason: string}>}} DocNamesReport
84
+ */
85
+
86
+ /**
87
+ * Each component name a template gives in `exampleFor` or `componentsUsed`
88
+ * that could not be judged. Present when the manifest loads. A name neither
89
+ * the package nor Core has, and the template does not import, is an
90
+ * `unknown_block_component` note beside the issues, with its fix in the
91
+ * message (it becomes a warning in the next minor release), so `findings` is
92
+ * always empty;
93
+ * `unchecked` lists each name that cannot be judged: one the template may
94
+ * reach through anything other than named imports and re-exports from
95
+ * Core, React, StyleX, local helpers or the package's own entry (an import from another
96
+ * package, a default or namespace import, an alias of or member read off an imported
97
+ * binding, require(), a dynamic import(), a local module this check cannot
98
+ * read), or, without Core installed, any name Core would have to resolve: `file` (the template doc, package-relative),
99
+ * `name`, and `reason`.
100
+ *
101
+ * @typedef {{status: 'checked', findings: [], unchecked: Array<{file: string, name: string, reason: string}>}} BlockComponentsReport
102
+ */
103
+
57
104
  export {};
105
+
106
+ /**
107
+ * An import the public-import check could not judge.
108
+ * @typedef {object} PublicImportUnchecked
109
+ * @property {string} file package-relative file that names it
110
+ * @property {string} specifier the import specifier
111
+ * @property {string} reason why it was not checked
112
+ */
113
+
114
+ /**
115
+ * The public-import check's report on validate's result: `unchecked` lists
116
+ * what it could not judge, never counted or failed on. Its findings are
117
+ * notes on the result (`data.notes`), so `findings` stays empty.
118
+ * @typedef {object} PublicImportsReport
119
+ * @property {'checked'} status
120
+ * @property {never[]} findings
121
+ * @property {PublicImportUnchecked[]} unchecked
122
+ */
@@ -62,7 +62,7 @@ export const doc = {
62
62
  {
63
63
  type: 'integration.validate',
64
64
  description:
65
- 'The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means "not looked at", not "healthy"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked.',
65
+ "The result envelope: `data.validated`, false when nothing was validated — with no `package.json` at all, `data.issues` carries one `no_package` error-severity issue so the command exits 1; with a `package.json` but no integration manifest, `data.issues` is empty, which means \"not looked at\", not \"healthy\"; `data.name` and `data.version` of the validated package (both null when `data.validated` is false; `data.name` is `(local package)` when the local package.json has no readable name), plus `data.issues`, an AstryxIntegrationIssue[] of {code, severity: `warning` | `error`, message, fix?, file?, line?}: `fix` is the change that resolves the issue, and `file` and `line` where it is, relative to the package, when the check knows them; and `data.notes` when there are any: {code, message} information that fails nothing, such as `invalid_cli_command` for a `cliCommand` that was ignored as malformed and `cli_peer_version` when the running CLI is outside the `@astryxdesign/cli` peer range of the package, and the package layout findings added after the last minor release, each with its fix in the message: `duplicate_component_doc`, `symlinked_root`, `unreadable_file`, `invalid_package_json` (no `name` or `version`), `no_provider_id`, and `source_without_component_doc` for a doc whose file name differs from its source only in letter case where the two still pair; and `doc_name_mismatch` and `unknown_block_component` (see `docNames` and `blockComponents`); they become warnings in the next minor release. A `runner_command` note lists each Astryx command a topic writes with a package runner, with its file, line and the bare command to write. When the manifest loads, `data.docTypes` holds the doc type check: `status` (`checked` | `skipped`), `reason` when skipped, `typescript`, `docs` (doc values checked), `findings` ({doc, line, export, type, field, problem: `unknown_field` | `missing_field` | `wrong_type`, severity: `warning`, message, fix}), `unchecked` ({doc, reason}: a doc that could not be fully checked, or a root its reader cannot read), and `fixtures` when the components or docs root holds test fixture docs under `__tests__`: how many, none of them checked. When the manifest loads, `data.docNames` lists the component doc names it could not judge: `status` (`checked`), `findings` (always empty; a doc name the module its import names provably does not export is a `doc_name_mismatch` note, with its fix in the message) and `unchecked` ({file, name, reason}: a doc whose `name` differs from the name it is listed under and whose source exports cannot all be read, such as a re-export from another package). When the manifest loads, `data.blockComponents` lists the component names templates give in `exampleFor` or `componentsUsed` that could not be judged: `status` (`checked`), `findings` (always empty; a name neither the package nor Core has, and the template does not import, is an `unknown_block_component` note, with its fix in the message) and `unchecked` ({file, name, reason}: a name the template may reach through anything other than named imports and re-exports from Core, React, StyleX, local helpers or the entry of the package itself, such as an import from another package, a default or namespace import, an alias of or member read off an imported binding, require() or a dynamic import(), or a local module that cannot be read, or any name Core would have to resolve when Core is not installed). Since 0.7.3 each import apps cannot use is a note in `data.notes`, its fix inside the message, listed only: it does not fail this command or `integration check --strict`, and fails `--strict` from the next minor release. The codes are `component_import_not_exported`, `component_import_other_package`, `component_import_missing_name`, `example_import_not_exported`, `example_import_missing_name`, `template_import_not_exported`, `template_import_outside_root`, `template_private_import`, `template_import_missing_name` and `template_no_default_export`. When the manifest loads, `data.publicImports` is `{status: 'checked', findings: [], unchecked}`: `unchecked` lists each import the check could not judge, as {file, specifier, reason}, the reason starting `example <label>:` for an import in a component example: an `exports` target not built yet; a module whose export list cannot be read in full (CommonJS, or a declaration file it cannot read); a root import in a package with no `exports` (the root module `main` names is not read); every name an import (other than a component doc's own component) names that its module does not export, while a TypeScript file in the package has a `declare module` block for a relative path or the package's own name or a subpath of it, which can add names to that module (a `declare module` in a comment, `declare global`, a wildcard such as `'*.css'`, and another package's name do not count; a file whose text has `declare module` but that cannot be parsed counts); the same for every such name when the package has more than 5,000 files to search for that block; a deep path into build output not built yet in a package with no `exports`; a template import of Core when `@astryxdesign/core` is not installed beside the package (a `packages/core` of the workspace under another name does not count); every import of the package's own name when package.json has no `name` or a `name` that is not a bare package name; one entry for the whole check when package.json cannot be read; and an import of a subpath whose `exports` entry has only a `types` target, unless it is `import type`, every binding is an inline `type`, or every name it imports is a type its types file declares: a value import of a name that file does not declare as a type, a namespace or side-effect import, or any import when the types file cannot be read (it may be build output). `integration check` counts the unchecked as not compared; they never fail it.",
66
66
  },
67
67
  ],
68
68
  examples: [
@@ -0,0 +1,28 @@
1
+ # Search ordering data
2
+
3
+ `astryx search` decides **what matches**, and each match's score and reason, with the lexical ranker (`_lexical.mjs` and the files it imports). The files in this folder only decide **the order of matches inside one score band**: they never add or drop a match, change a score, or move a match past one of another band or kind (doc or not). The bands are scores 195 and up, 188–194, 170–187, 160–169, 151–159, 100–150, 55–99, and under 55. A band can be wide (55–99 holds keyword matches beside one-word description hits), so inside a band a lower score can lead a higher one.
4
+
5
+ ## Rule
6
+
7
+ `spec:AST-083` owns search's result order; this file describes the data that implements it. Inside one score band, a searcher's static weights decide the order. Matches with the same score move together as one block, in the lexical ranker's order, placed by the learned position of the block's first match: moving each one on its own breaks search's existing rules for tied matches. Matches never cross bands or kinds. There is no model runtime: every number is a plain static value read at load time.
8
+
9
+ ## Files
10
+
11
+ | File | What it holds |
12
+ | ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
13
+ | `tree.weights.json` | The root classifier: for each query word or word pair, one number per class (component, hook, doc, template, theme, none). The query's tokens vote, and a topic searcher takes the query only when its class wins by the floor in `tree.mjs`. |
14
+ | `_main-searcher.weights.json`, `_doc-searcher.weights.json`, `_template-searcher.weights.json` | One weight, mean and spread per signal for each searcher (see `SIGNALS` and `PER_DOMAIN` in `_features.mjs`). A match's place inside its band is the weighted sum of its standardized signals. |
15
+ | `_cards.json` | One card per Core component and hook: what it is, the words people use for it, and its main props, written from the item's own source. Cards feed one signal, word overlap with the card. |
16
+
17
+ The signals are counts over the query and each entry's own text: the lexical score and rank, BM25 over the entry's name, docs text and card, how many query words the entry covers, whether the query holds the entry's name, and the classifier's guess of the domain.
18
+
19
+ ## Status
20
+
21
+ These files are static and reviewed. They are not computed when the CLI runs, and nothing at run time writes them.
22
+
23
+ ## Refreshing
24
+
25
+ - A Core component or hook without a card is still matched and scored as usual; inside its band it is ordered by its other signals.
26
+ - When Core adds or renames items, a reviewed change adds or updates their cards and, if needed, refreshed weights.
27
+ - Any refresh must keep every test that pins search's behavior passing, including the ordering invariants in `_order.test.mjs`. It must also keep the `astryx search` output's matches, scores and reasons identical to the lexical ranker's.
28
+ - Any refresh must also be measured as `spec:AST-083` FR6 requires: against the held-out, fresh and synthetic evaluation sets, with no row worse than the previous order (a row is worse when the paired 95% confidence interval of its change lies entirely below zero).
@@ -1,11 +1,91 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /** @typedef {import('./_lexical.mjs').Candidate} Candidate */
4
5
  /**
5
6
  * The Core a typed search reads: the project's, else the release's own,
6
- * installed into the per-user cache first when needed. Throws as
7
- * requireCoreDir does.
7
+ * installed into the per-user cache first when needed (a network install and
8
+ * an npm subprocess; spec AST-081 FR3). Throws as requireCoreDir does.
8
9
  * @param {string} cwd
9
10
  * @returns {string}
10
11
  */
11
12
  export function requireSearchCoreDir(cwd: string): string;
13
+ /**
14
+ * Gathers every candidate the query's domains hold.
15
+ *
16
+ * @param {{cwd?: string, type?: string}} options
17
+ * @returns {Promise<{all: Candidate[], components: Candidate[], searchedComponents: boolean, outside: boolean, coreSkipped: string | null}>}
18
+ */
19
+ export function gatherCandidates(options: {
20
+ cwd?: string;
21
+ type?: string;
22
+ }): Promise<{
23
+ all: Candidate[];
24
+ components: Candidate[];
25
+ searchedComponents: boolean;
26
+ outside: boolean;
27
+ coreSkipped: string | null;
28
+ }>;
29
+ /**
30
+ * gatherCandidates, reused within one process: a later search in the same
31
+ * folder, for the same `type`, ranks the candidates an earlier search
32
+ * gathered when none of the files that gather read, and none of the folders
33
+ * it listed or probed, changed since (each is checked by its change time and
34
+ * size, so an edited doc in a linked package is seen on the next call). A
35
+ * long-running caller (a docs site's search, an agent harness) then pays the
36
+ * gather once. A one-shot `astryx search` gathers once, as before.
37
+ * @param {{cwd?: string, type?: string}} options
38
+ * @returns {Promise<Gathered>}
39
+ */
40
+ export function gatherCandidatesReused(options: {
41
+ cwd?: string;
42
+ type?: string;
43
+ }): Promise<Gathered>;
44
+ /**
45
+ * The search tree's static data, read once: the entry cards and each node's
46
+ * weights file.
47
+ *
48
+ * These files are static, reviewed data that only order matches inside a score
49
+ * band; ORDERING.md beside them says what each holds and how
50
+ * they are refreshed.
51
+ * @returns {SearchData}
52
+ */
53
+ export function loadSearchData(): SearchData;
54
+ export { componentKeywords } from "./_gather-components.mjs";
55
+ export type Candidate = import("./_lexical.mjs").Candidate;
56
+ export type Gathered = Awaited<ReturnType<typeof gatherCandidates>>;
57
+ export type SearcherWeights = {
58
+ w: number[];
59
+ mu: number[];
60
+ sd: number[];
61
+ };
62
+ export type SearchData = {
63
+ /**
64
+ * Each Core component's and hook's source-built card: what it is, the words
65
+ * people type for it, its main props.
66
+ */
67
+ cards: Record<string, {
68
+ what?: string;
69
+ synonyms?: string[];
70
+ props?: string[];
71
+ }>;
72
+ /**
73
+ * The root classifier's weights.
74
+ */
75
+ router: import("../../foundation/route/route.mjs").ClassifierWeights;
76
+ /**
77
+ * The main searcher's weights.
78
+ */
79
+ main: SearcherWeights;
80
+ /**
81
+ * The doc searcher's weights.
82
+ */
83
+ doc: SearcherWeights;
84
+ /**
85
+ * The template searcher's weights.
86
+ */
87
+ template: SearcherWeights;
88
+ };
89
+ export type SearchCatalog = Awaited<ReturnType<typeof gatherCandidates>> & {
90
+ data: SearchData;
91
+ };
@@ -1,25 +1,172 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file Environment adapter for search: locating the Core a search reads,
5
- * including the network install and npm subprocess that fetch a release's
6
- * own Core outside a project (spec AST-081 FR3; architecture:cli-surface
7
- * INV21).
8
- *
9
- * @input the folder a search runs in
10
- * @output the Core folder a search reads
11
- * @position packages/cli/api/search — imported by search.mjs only
4
+ * @file Search's adapter: the only place search reads the environment. It
5
+ * gathers every candidate from the domains a query asks for (one file per
6
+ * domain, _gather-*.mjs) and loads the tree's static data before it runs.
12
7
  */
13
8
 
9
+ import {readFileSync} from 'node:fs';
10
+ import * as path from 'node:path';
14
11
  import {requireCoreDir} from '../../foundation/fs/paths.mjs';
12
+ import {recordReads, unchangedSince} from '../../foundation/fs/read-record.mjs';
13
+ import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
14
+ import {coreDirOrThrow} from '../error.mjs';
15
+ import {CORELESS_DOMAINS} from './_query.mjs';
16
+ import {gatherComponents} from './_gather-components.mjs';
17
+ import {gatherHooks} from './_gather-hooks.mjs';
18
+ import {gatherDocs} from './_gather-docs.mjs';
19
+ import {gatherTemplates, gatherThemes} from './_gather-templates.mjs';
20
+
21
+ export {componentKeywords} from './_gather-components.mjs';
22
+
23
+ /** @typedef {import('./_lexical.mjs').Candidate} Candidate */
15
24
 
16
25
  /**
17
26
  * The Core a typed search reads: the project's, else the release's own,
18
- * installed into the per-user cache first when needed. Throws as
19
- * requireCoreDir does.
27
+ * installed into the per-user cache first when needed (a network install and
28
+ * an npm subprocess; spec AST-081 FR3). Throws as requireCoreDir does.
20
29
  * @param {string} cwd
21
30
  * @returns {string}
22
31
  */
23
32
  export function requireSearchCoreDir(cwd) {
24
33
  return requireCoreDir(cwd);
25
34
  }
35
+
36
+ /**
37
+ * Gathers every candidate the query's domains hold.
38
+ *
39
+ * @param {{cwd?: string, type?: string}} options
40
+ * @returns {Promise<{all: Candidate[], components: Candidate[], searchedComponents: boolean, outside: boolean, coreSkipped: string | null}>}
41
+ */
42
+ export async function gatherCandidates(options) {
43
+ const {cwd = process.cwd(), type} = options;
44
+ // `astryx docs` reads docs without @astryxdesign/core, and `astryx theme
45
+ // list` reads themes without it (bundled themes need no project), so a
46
+ // search of either must too. Every other domain reads core: asked for by
47
+ // name, it is an error without core; an open search then covers the docs
48
+ // and themes alone.
49
+ const needsCore = !type || !CORELESS_DOMAINS.includes(type);
50
+ // A domain that reads Core gets it as `component` does: the project's, else
51
+ // the answering release's own, installed into the per-user cache on first
52
+ // need (spec AST-081 FR3). Asked for by name, a Core that cannot be had is
53
+ // the error; an open search answers from the rest and says what it skipped
54
+ // and why, never silently.
55
+ /** @type {string | null} */
56
+ let coreDir = null;
57
+ /** @type {string | null} */
58
+ let coreSkipped = null;
59
+ if (needsCore && type) {
60
+ coreDir = coreDirOrThrow(requireSearchCoreDir, cwd);
61
+ } else if (needsCore) {
62
+ try {
63
+ coreDir = requireSearchCoreDir(cwd);
64
+ } catch (error) {
65
+ coreSkipped = /** @type {Error} */ (error).message;
66
+ }
67
+ }
68
+
69
+ // Gather candidates from each requested domain in parallel.
70
+ /** @param {string} d */
71
+ const wants = d =>
72
+ (!type && (coreDir != null || CORELESS_DOMAINS.includes(d))) || type === d;
73
+ const [components, hooks, docTopics, templates, themes] = await Promise.all([
74
+ wants('component')
75
+ ? gatherComponents(/** @type {string} */ (coreDir), cwd)
76
+ : [],
77
+ wants('hook') ? gatherHooks(/** @type {string} */ (coreDir)) : [],
78
+ wants('doc') ? gatherDocs(cwd) : [],
79
+ wants('template') ? gatherTemplates(cwd) : [],
80
+ wants('theme') ? gatherThemes(cwd) : [],
81
+ ]);
82
+
83
+ const all = [...components, ...hooks, ...docTopics, ...templates, ...themes];
84
+ // Outside a project a theme cannot be added to an app, so its command forks
85
+ // the source instead (spec AST-081 FR3).
86
+ const outside = themes.length > 0 && isOutsideProject(cwd);
87
+ return {
88
+ all,
89
+ components,
90
+ searchedComponents: wants('component'),
91
+ outside,
92
+ coreSkipped,
93
+ };
94
+ }
95
+
96
+ /**
97
+ * @typedef {Awaited<ReturnType<typeof gatherCandidates>>} Gathered
98
+ * @type {Map<string, {reads: Map<string, string>, value: Promise<Gathered>}>}
99
+ */
100
+ const gathered = new Map();
101
+
102
+ /**
103
+ * gatherCandidates, reused within one process: a later search in the same
104
+ * folder, for the same `type`, ranks the candidates an earlier search
105
+ * gathered when none of the files that gather read, and none of the folders
106
+ * it listed or probed, changed since (each is checked by its change time and
107
+ * size, so an edited doc in a linked package is seen on the next call). A
108
+ * long-running caller (a docs site's search, an agent harness) then pays the
109
+ * gather once. A one-shot `astryx search` gathers once, as before.
110
+ * @param {{cwd?: string, type?: string}} options
111
+ * @returns {Promise<Gathered>}
112
+ */
113
+ export async function gatherCandidatesReused(options) {
114
+ const cwd = path.resolve(options.cwd ?? process.cwd());
115
+ const key = `${cwd}\0${options.type ?? ''}`;
116
+ const hit = gathered.get(key);
117
+ if (hit && unchangedSince(hit.reads)) return hit.value;
118
+ /** @type {Map<string, string>} */
119
+ const seen = new Map();
120
+ const value = recordReads(seen, () => gatherCandidates({...options, cwd}));
121
+ try {
122
+ await value;
123
+ } catch (error) {
124
+ if (gathered.get(key)?.value === value) gathered.delete(key);
125
+ throw error;
126
+ }
127
+ // Each path's state was taken as it was first read, so an edit made while
128
+ // the gather ran shows as a change on the next call.
129
+ gathered.set(key, {reads: seen, value});
130
+ return value;
131
+ }
132
+
133
+ /**
134
+ * @typedef {{w: number[], mu: number[], sd: number[]}} SearcherWeights
135
+ * @typedef {object} SearchData
136
+ * @property {Record<string, {what?: string, synonyms?: string[], props?: string[]}>} cards
137
+ * Each Core component's and hook's source-built card: what it is, the words
138
+ * people type for it, its main props.
139
+ * @property {import('../../foundation/route/route.mjs').ClassifierWeights} router The root classifier's weights.
140
+ * @property {SearcherWeights} main The main searcher's weights.
141
+ * @property {SearcherWeights} doc The doc searcher's weights.
142
+ * @property {SearcherWeights} template The template searcher's weights.
143
+ * @typedef {Awaited<ReturnType<typeof gatherCandidates>> & {data: SearchData}} SearchCatalog
144
+ */
145
+
146
+ /** @type {SearchData | null} */
147
+ let searchData = null;
148
+
149
+ /**
150
+ * The search tree's static data, read once: the entry cards and each node's
151
+ * weights file.
152
+ *
153
+ * These files are static, reviewed data that only order matches inside a score
154
+ * band; ORDERING.md beside them says what each holds and how
155
+ * they are refreshed.
156
+ * @returns {SearchData}
157
+ */
158
+ export function loadSearchData() {
159
+ if (!searchData) {
160
+ /** @param {string} file */
161
+ const read = file =>
162
+ JSON.parse(readFileSync(new URL(file, import.meta.url), 'utf8'));
163
+ searchData = {
164
+ cards: read('./_cards.json'),
165
+ router: read('./tree.weights.json'),
166
+ main: read('./_main-searcher.weights.json'),
167
+ doc: read('./_doc-searcher.weights.json'),
168
+ template: read('./_template-searcher.weights.json'),
169
+ };
170
+ }
171
+ return searchData;
172
+ }
@@ -0,0 +1,173 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Tests for search's adapter: a long-running caller reuses the gathered
5
+ * candidates while their inputs are unchanged (gatherCandidatesReused), and
6
+ * gathers again when an input changes or for another folder or `type`.
7
+ *
8
+ * Whether inputs changed is read-record's answer (tested in
9
+ * read-record.test.mjs). Other tests running at the same time change shared
10
+ * folders a gather reads (the temp folder, the repository root), so here the
11
+ * reuse case holds that answer at "unchanged", and every other case only
12
+ * checks that a change forces a new gather, which concurrent changes cannot
13
+ * undo.
14
+ */
15
+
16
+ import {describe, it, expect, vi} from 'vitest';
17
+ import * as fs from 'node:fs';
18
+ import * as os from 'node:os';
19
+ import * as path from 'node:path';
20
+ import * as readRecord from '../../foundation/fs/read-record.mjs';
21
+ import {gatherCandidates, gatherCandidatesReused} from './_adapter.mjs';
22
+
23
+ vi.mock('../../foundation/fs/read-record.mjs', async original => {
24
+ const real = /** @type {typeof readRecord} */ (await original());
25
+ return {...real, unchangedSince: vi.fn(real.unchangedSince)};
26
+ });
27
+ const unchangedSince = vi.mocked(readRecord.unchangedSince);
28
+
29
+ const SLOW = 60_000;
30
+
31
+ /** A folder with only a package.json: a docs search there reads the CLI's docs. */
32
+ function scratchProject() {
33
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-gather-reuse-'));
34
+ fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"app"}');
35
+ return dir;
36
+ }
37
+
38
+ describe('gatherCandidatesReused', () => {
39
+ it(
40
+ 'reuses the gathered candidates while the inputs are unchanged',
41
+ async () => {
42
+ const cwd = scratchProject();
43
+ const first = await gatherCandidatesReused({cwd, type: 'doc'});
44
+ unchangedSince.mockReturnValueOnce(true);
45
+ expect(await gatherCandidatesReused({cwd, type: 'doc'})).toBe(first);
46
+ expect(first.all.length).toBeGreaterThan(0);
47
+ // The same candidates a fresh gather finds.
48
+ expect(JSON.parse(JSON.stringify(first))).toEqual(
49
+ JSON.parse(JSON.stringify(await gatherCandidates({cwd, type: 'doc'}))),
50
+ );
51
+ },
52
+ SLOW,
53
+ );
54
+
55
+ it(
56
+ 'gathers again when an input file changes',
57
+ async () => {
58
+ const cwd = scratchProject();
59
+ const first = await gatherCandidatesReused({cwd, type: 'doc'});
60
+ const later = new Date(Date.now() + 5_000);
61
+ fs.utimesSync(path.join(cwd, 'package.json'), later, later);
62
+ expect(await gatherCandidatesReused({cwd, type: 'doc'})).not.toBe(first);
63
+ fs.writeFileSync(
64
+ path.join(cwd, 'astryx.config.mjs'),
65
+ 'export default {};\n',
66
+ );
67
+ expect(await gatherCandidatesReused({cwd, type: 'doc'})).not.toBe(first);
68
+ },
69
+ SLOW,
70
+ );
71
+
72
+ it(
73
+ 'keeps one entry per folder and type',
74
+ async () => {
75
+ const cwd = scratchProject();
76
+ const docs = await gatherCandidatesReused({cwd, type: 'doc'});
77
+ const themes = await gatherCandidatesReused({cwd, type: 'theme'});
78
+ expect(themes).not.toBe(docs);
79
+ expect(themes.all.every(c => c.domain === 'theme')).toBe(true);
80
+ expect(
81
+ await gatherCandidatesReused({cwd: scratchProject(), type: 'doc'}),
82
+ ).not.toBe(docs);
83
+ },
84
+ SLOW,
85
+ );
86
+
87
+ it(
88
+ 'gathers again when a file the gather read changes, in a linked package too',
89
+ async () => {
90
+ // A consumer whose integration is a symlink to a package folder
91
+ // elsewhere, as a workspace package is.
92
+ const dir = fs.mkdtempSync(
93
+ path.join(process.cwd(), '.astryx-gather-reuse-'),
94
+ );
95
+ const pkg = fs.mkdtempSync(
96
+ path.join(os.tmpdir(), 'astryx-linked-widgets-'),
97
+ );
98
+ try {
99
+ fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"consumer"}');
100
+ fs.writeFileSync(
101
+ path.join(dir, 'astryx.config.mjs'),
102
+ "export default { integrations: ['@acme/widgets'] };\n",
103
+ );
104
+ fs.mkdirSync(
105
+ path.join(dir, 'node_modules', '@astryxdesign', 'core', 'src'),
106
+ {
107
+ recursive: true,
108
+ },
109
+ );
110
+ fs.mkdirSync(path.join(pkg, 'components'));
111
+ fs.writeFileSync(
112
+ path.join(pkg, 'package.json'),
113
+ '{"name":"@acme/widgets","version":"1.0.0"}',
114
+ );
115
+ fs.writeFileSync(
116
+ path.join(pkg, 'astryx.integration.mjs'),
117
+ "export default { components: './components' };\n",
118
+ );
119
+ fs.writeFileSync(
120
+ path.join(pkg, 'components', 'FancyGizmo.doc.mjs'),
121
+ `export default {
122
+ type: 'component',
123
+ name: 'FancyGizmo',
124
+ keywords: ['gizmo'],
125
+ usage: {description: 'A fancy part.'},
126
+ props: [],
127
+ };\n`,
128
+ );
129
+ fs.writeFileSync(
130
+ path.join(pkg, 'components', 'FancyGizmo.tsx'),
131
+ 'export function FancyGizmo() { return null; }\n',
132
+ );
133
+ fs.mkdirSync(path.join(dir, 'node_modules', '@acme'));
134
+ fs.symlinkSync(
135
+ pkg,
136
+ path.join(dir, 'node_modules', '@acme', 'widgets'),
137
+ 'dir',
138
+ );
139
+ const options = {cwd: dir, type: 'component'};
140
+ const first = await gatherCandidatesReused(options);
141
+ expect(first.all.map(c => c.name)).toContain('FancyGizmo');
142
+
143
+ // A new component in the linked package: its folder changed.
144
+ fs.writeFileSync(
145
+ path.join(pkg, 'components', 'TinySprocket.doc.mjs'),
146
+ `export default {
147
+ type: 'component',
148
+ name: 'TinySprocket',
149
+ keywords: ['sprocket'],
150
+ usage: {description: 'A small part.'},
151
+ props: [],
152
+ };\n`,
153
+ );
154
+ fs.writeFileSync(
155
+ path.join(pkg, 'components', 'TinySprocket.tsx'),
156
+ 'export function TinySprocket() { return null; }\n',
157
+ );
158
+ const second = await gatherCandidatesReused(options);
159
+ expect(second).not.toBe(first);
160
+ expect(second.all.map(c => c.name)).toContain('TinySprocket');
161
+
162
+ // An edited file the gather read: the linked package's manifest.
163
+ const later = new Date(Date.now() + 5_000);
164
+ fs.utimesSync(path.join(pkg, 'package.json'), later, later);
165
+ expect(await gatherCandidatesReused(options)).not.toBe(second);
166
+ } finally {
167
+ fs.rmSync(dir, {recursive: true, force: true});
168
+ fs.rmSync(pkg, {recursive: true, force: true});
169
+ }
170
+ },
171
+ SLOW,
172
+ );
173
+ });
@@ -0,0 +1,40 @@
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
+ * Score a single candidate against the search term across name, keywords,
6
+ * and prose signals. Returns the best (highest) score plus a human reason,
7
+ * or null if nothing matched above the floor.
8
+ *
9
+ * @param {string} term - Lowercased search term.
10
+ * @param {object} candidate
11
+ * @param {string} candidate.name - Primary identifier (component/hook name, topic, template name).
12
+ * @param {string[]} [candidate.aliases] - Other names, scored like the name (a theme's display name).
13
+ * @param {string} [candidate.domain] - A component, hook, or template name
14
+ * also matches typed as words: `command palette` is CommandPalette.
15
+ * @param {string[]} [candidate.keywords] - Authored intent (componentsUsed, category words).
16
+ * @param {string[]} [candidate.weakKeywords] - Derived signal (components a page renders).
17
+ * @param {string} [candidate.description]
18
+ * @param {string[]} [candidate.prose] - Extra free-text blobs (doc section text, best practices).
19
+ * @param {string[]} [candidate.guidance] - Usage guidance (features, best practices) — scored a tier below description.
20
+ * @param {{fuzzy?: boolean, joins?: boolean}} [opts] - `fuzzy`: allow edit-distance (typo) matches. Default true; multi-word queries pass false. `joins`: read a spaced query joined into a name or keyword (default true); off when the query names an entry outright.
21
+ * @returns {{score: number, reason: string, alias?: 'partial' | 'keyword'} | null}
22
+ * `alias` marks a hit that read the query's words joined.
23
+ */
24
+ export function scoreCandidate(term: string, { name, aliases, domain, keywords, weakKeywords, description, prose, guidance, }: {
25
+ name: string;
26
+ aliases?: string[] | undefined;
27
+ domain?: string | undefined;
28
+ keywords?: string[] | undefined;
29
+ weakKeywords?: string[] | undefined;
30
+ description?: string | undefined;
31
+ prose?: string[] | undefined;
32
+ guidance?: string[] | undefined;
33
+ }, { fuzzy, joins }?: {
34
+ fuzzy?: boolean;
35
+ joins?: boolean;
36
+ }): {
37
+ score: number;
38
+ reason: string;
39
+ alias?: "partial" | "keyword";
40
+ } | null;