@dxos/app-framework 0.8.4-main.b97322e → 0.8.4-main.bc2380dfbc

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 (571) hide show
  1. package/.storybook/main.mts +9 -0
  2. package/.storybook/preview.mts +8 -0
  3. package/LICENSE +102 -5
  4. package/README.md +1 -1
  5. package/dist/lib/browser/capability-HRFPP52W.mjs +35 -0
  6. package/dist/lib/browser/capability-HRFPP52W.mjs.map +7 -0
  7. package/dist/lib/browser/capability-VQ236TY5.mjs +38 -0
  8. package/dist/lib/browser/capability-VQ236TY5.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-23D4SJUE.mjs +42 -0
  10. package/dist/lib/browser/chunk-23D4SJUE.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-3JWJXGLK.mjs +79 -0
  12. package/dist/lib/browser/chunk-3JWJXGLK.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-45CHLTBV.mjs +34 -0
  14. package/dist/lib/browser/chunk-45CHLTBV.mjs.map +7 -0
  15. package/dist/lib/browser/chunk-66IXTIVK.mjs +48 -0
  16. package/dist/lib/browser/chunk-66IXTIVK.mjs.map +7 -0
  17. package/dist/lib/browser/chunk-6GZYCP73.mjs +422 -0
  18. package/dist/lib/browser/chunk-6GZYCP73.mjs.map +7 -0
  19. package/dist/lib/browser/chunk-7VZJR2OA.mjs +581 -0
  20. package/dist/lib/browser/chunk-7VZJR2OA.mjs.map +7 -0
  21. package/dist/lib/browser/chunk-FJ4765WW.mjs +8 -0
  22. package/dist/lib/browser/chunk-FJ4765WW.mjs.map +7 -0
  23. package/dist/lib/browser/chunk-FO3IYSLV.mjs +68 -0
  24. package/dist/lib/browser/chunk-FO3IYSLV.mjs.map +7 -0
  25. package/dist/lib/browser/chunk-G6Q2M2M5.mjs +218 -0
  26. package/dist/lib/browser/chunk-G6Q2M2M5.mjs.map +7 -0
  27. package/dist/lib/browser/chunk-J43JDWAV.mjs +1445 -0
  28. package/dist/lib/browser/chunk-J43JDWAV.mjs.map +7 -0
  29. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  30. package/dist/lib/browser/chunk-WBHCSOBW.mjs +80 -0
  31. package/dist/lib/browser/chunk-WBHCSOBW.mjs.map +7 -0
  32. package/dist/lib/browser/chunk-XLYULXAO.mjs +469 -0
  33. package/dist/lib/browser/chunk-XLYULXAO.mjs.map +7 -0
  34. package/dist/lib/browser/chunk-ZGJAZSNE.mjs +142 -0
  35. package/dist/lib/browser/chunk-ZGJAZSNE.mjs.map +7 -0
  36. package/dist/lib/browser/cli/index.mjs +76 -0
  37. package/dist/lib/browser/cli/index.mjs.map +7 -0
  38. package/dist/lib/browser/common/activation-events.mjs +24 -0
  39. package/dist/lib/browser/common/capabilities.mjs +46 -0
  40. package/dist/lib/browser/core/activation-event.mjs +20 -0
  41. package/dist/lib/browser/core/capability.mjs +30 -0
  42. package/dist/lib/browser/core/capability.mjs.map +7 -0
  43. package/dist/lib/browser/core/plugin-manager.mjs +19 -0
  44. package/dist/lib/browser/core/plugin-manager.mjs.map +7 -0
  45. package/dist/lib/browser/core/plugin.mjs +39 -0
  46. package/dist/lib/browser/core/plugin.mjs.map +7 -0
  47. package/dist/lib/browser/core/url-loader.mjs +24 -0
  48. package/dist/lib/browser/core/url-loader.mjs.map +7 -0
  49. package/dist/lib/browser/index.mjs +108 -156
  50. package/dist/lib/browser/index.mjs.map +4 -4
  51. package/dist/lib/browser/invoker-capability-CEL2L6GX.mjs +44 -0
  52. package/dist/lib/browser/invoker-capability-CEL2L6GX.mjs.map +7 -0
  53. package/dist/lib/browser/meta.json +1 -1
  54. package/dist/lib/browser/testing/index.mjs +236 -51
  55. package/dist/lib/browser/testing/index.mjs.map +4 -4
  56. package/dist/lib/browser/testing/react.mjs +78 -0
  57. package/dist/lib/browser/testing/react.mjs.map +7 -0
  58. package/dist/lib/browser/ui/index.mjs +48 -0
  59. package/dist/lib/browser/ui/index.mjs.map +7 -0
  60. package/dist/lib/node-esm/capability-GS3XJH74.mjs +39 -0
  61. package/dist/lib/node-esm/capability-GS3XJH74.mjs.map +7 -0
  62. package/dist/lib/node-esm/capability-I5P7ACFL.mjs +36 -0
  63. package/dist/lib/node-esm/capability-I5P7ACFL.mjs.map +7 -0
  64. package/dist/lib/node-esm/chunk-37Z53PXZ.mjs +10 -0
  65. package/dist/lib/node-esm/chunk-37Z53PXZ.mjs.map +7 -0
  66. package/dist/lib/node-esm/chunk-4RJL37GN.mjs +423 -0
  67. package/dist/lib/node-esm/chunk-4RJL37GN.mjs.map +7 -0
  68. package/dist/lib/node-esm/chunk-6XW6LET6.mjs +35 -0
  69. package/dist/lib/node-esm/chunk-6XW6LET6.mjs.map +7 -0
  70. package/dist/lib/node-esm/chunk-D347W3KO.mjs +143 -0
  71. package/dist/lib/node-esm/chunk-D347W3KO.mjs.map +7 -0
  72. package/dist/lib/node-esm/chunk-DW45NFLW.mjs +1446 -0
  73. package/dist/lib/node-esm/chunk-DW45NFLW.mjs.map +7 -0
  74. package/dist/lib/node-esm/chunk-EI4LYXFY.mjs +470 -0
  75. package/dist/lib/node-esm/chunk-EI4LYXFY.mjs.map +7 -0
  76. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  77. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  78. package/dist/lib/node-esm/chunk-KIFOQXD4.mjs +219 -0
  79. package/dist/lib/node-esm/chunk-KIFOQXD4.mjs.map +7 -0
  80. package/dist/lib/node-esm/chunk-SBS2YMPT.mjs +43 -0
  81. package/dist/lib/node-esm/chunk-SBS2YMPT.mjs.map +7 -0
  82. package/dist/lib/node-esm/chunk-SDJ4B2LU.mjs +80 -0
  83. package/dist/lib/node-esm/chunk-SDJ4B2LU.mjs.map +7 -0
  84. package/dist/lib/node-esm/chunk-V24UWT36.mjs +582 -0
  85. package/dist/lib/node-esm/chunk-V24UWT36.mjs.map +7 -0
  86. package/dist/lib/node-esm/chunk-WFSRZKBP.mjs +81 -0
  87. package/dist/lib/node-esm/chunk-WFSRZKBP.mjs.map +7 -0
  88. package/dist/lib/node-esm/chunk-WK7OIQKI.mjs +70 -0
  89. package/dist/lib/node-esm/chunk-WK7OIQKI.mjs.map +7 -0
  90. package/dist/lib/node-esm/chunk-XOCUANHO.mjs +49 -0
  91. package/dist/lib/node-esm/chunk-XOCUANHO.mjs.map +7 -0
  92. package/dist/lib/node-esm/cli/index.mjs +77 -0
  93. package/dist/lib/node-esm/cli/index.mjs.map +7 -0
  94. package/dist/lib/node-esm/common/activation-events.mjs +25 -0
  95. package/dist/lib/node-esm/common/activation-events.mjs.map +7 -0
  96. package/dist/lib/node-esm/common/capabilities.mjs +47 -0
  97. package/dist/lib/node-esm/common/capabilities.mjs.map +7 -0
  98. package/dist/lib/node-esm/core/activation-event.mjs +21 -0
  99. package/dist/lib/node-esm/core/activation-event.mjs.map +7 -0
  100. package/dist/lib/node-esm/core/capability.mjs +31 -0
  101. package/dist/lib/node-esm/core/capability.mjs.map +7 -0
  102. package/dist/lib/node-esm/core/plugin-manager.mjs +20 -0
  103. package/dist/lib/node-esm/core/plugin-manager.mjs.map +7 -0
  104. package/dist/lib/node-esm/core/plugin.mjs +40 -0
  105. package/dist/lib/node-esm/core/plugin.mjs.map +7 -0
  106. package/dist/lib/node-esm/core/url-loader.mjs +25 -0
  107. package/dist/lib/node-esm/core/url-loader.mjs.map +7 -0
  108. package/dist/lib/node-esm/index.mjs +108 -156
  109. package/dist/lib/node-esm/index.mjs.map +4 -4
  110. package/dist/lib/node-esm/invoker-capability-QKUKN2MF.mjs +45 -0
  111. package/dist/lib/node-esm/invoker-capability-QKUKN2MF.mjs.map +7 -0
  112. package/dist/lib/node-esm/meta.json +1 -1
  113. package/dist/lib/node-esm/testing/index.mjs +236 -51
  114. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  115. package/dist/lib/node-esm/testing/react.mjs +79 -0
  116. package/dist/lib/node-esm/testing/react.mjs.map +7 -0
  117. package/dist/lib/node-esm/ui/index.mjs +49 -0
  118. package/dist/lib/node-esm/ui/index.mjs.map +7 -0
  119. package/dist/plugin/node-esm/index.mjs +893 -0
  120. package/dist/plugin/node-esm/index.mjs.map +7 -0
  121. package/dist/plugin/node-esm/meta.json +1 -0
  122. package/dist/types/src/cli/cli.d.ts +39 -0
  123. package/dist/types/src/cli/cli.d.ts.map +1 -0
  124. package/dist/types/src/cli/index.d.ts +2 -0
  125. package/dist/types/src/cli/index.d.ts.map +1 -0
  126. package/dist/types/src/common/activation-events.d.ts +27 -0
  127. package/dist/types/src/common/activation-events.d.ts.map +1 -0
  128. package/dist/types/src/common/annotations.d.ts +1 -0
  129. package/dist/types/src/common/annotations.d.ts.map +1 -0
  130. package/dist/types/src/common/capabilities.d.ts +110 -123
  131. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  132. package/dist/types/src/common/index.d.ts +4 -8
  133. package/dist/types/src/common/index.d.ts.map +1 -1
  134. package/dist/types/src/common/operations.d.ts +19 -0
  135. package/dist/types/src/common/operations.d.ts.map +1 -0
  136. package/dist/types/src/common/translations.d.ts +8 -8
  137. package/dist/types/src/common/translations.d.ts.map +1 -1
  138. package/dist/types/src/context.d.ts +5 -0
  139. package/dist/types/src/context.d.ts.map +1 -0
  140. package/dist/types/src/core/{events.d.ts → activation-event.d.ts} +11 -11
  141. package/dist/types/src/core/activation-event.d.ts.map +1 -0
  142. package/dist/types/src/core/capability-manager.d.ts +48 -0
  143. package/dist/types/src/core/capability-manager.d.ts.map +1 -0
  144. package/dist/types/src/core/capability-manager.test.d.ts +2 -0
  145. package/dist/types/src/core/capability-manager.test.d.ts.map +1 -0
  146. package/dist/types/src/core/capability.d.ts +156 -0
  147. package/dist/types/src/core/capability.d.ts.map +1 -0
  148. package/dist/types/src/core/edge-registry-plugin-provider.d.ts +30 -0
  149. package/dist/types/src/core/edge-registry-plugin-provider.d.ts.map +1 -0
  150. package/dist/types/src/core/index.d.ts +11 -4
  151. package/dist/types/src/core/index.d.ts.map +1 -1
  152. package/dist/types/src/core/plugin-asset-cache.d.ts +71 -0
  153. package/dist/types/src/core/plugin-asset-cache.d.ts.map +1 -0
  154. package/dist/types/src/core/plugin-manager.d.ts +298 -0
  155. package/dist/types/src/core/plugin-manager.d.ts.map +1 -0
  156. package/dist/types/src/core/plugin-manager.test.d.ts +2 -0
  157. package/dist/types/src/core/plugin-manager.test.d.ts.map +1 -0
  158. package/dist/types/src/core/plugin-manifest.d.ts +101 -0
  159. package/dist/types/src/core/plugin-manifest.d.ts.map +1 -0
  160. package/dist/types/src/core/plugin-manifest.test.d.ts +2 -0
  161. package/dist/types/src/core/plugin-manifest.test.d.ts.map +1 -0
  162. package/dist/types/src/core/plugin.d.ts +265 -37
  163. package/dist/types/src/core/plugin.d.ts.map +1 -1
  164. package/dist/types/src/core/registry.d.ts +107 -0
  165. package/dist/types/src/core/registry.d.ts.map +1 -0
  166. package/dist/types/src/core/url-loader.d.ts +127 -0
  167. package/dist/types/src/core/url-loader.d.ts.map +1 -0
  168. package/dist/types/src/core/url-loader.test.d.ts +2 -0
  169. package/dist/types/src/core/url-loader.test.d.ts.map +1 -0
  170. package/dist/types/src/helpers.d.ts.map +1 -1
  171. package/dist/types/src/index.d.ts +3 -4
  172. package/dist/types/src/index.d.ts.map +1 -1
  173. package/dist/types/src/plugin-operation/OperationPlugin.d.ts +3 -0
  174. package/dist/types/src/plugin-operation/OperationPlugin.d.ts.map +1 -0
  175. package/dist/types/src/plugin-operation/history/capability.d.ts +7 -0
  176. package/dist/types/src/plugin-operation/history/capability.d.ts.map +1 -0
  177. package/dist/types/src/plugin-operation/history/errors.d.ts +32 -0
  178. package/dist/types/src/plugin-operation/history/errors.d.ts.map +1 -0
  179. package/dist/types/src/plugin-operation/history/history-tracker.d.ts +18 -0
  180. package/dist/types/src/plugin-operation/history/history-tracker.d.ts.map +1 -0
  181. package/dist/types/src/plugin-operation/history/history-tracker.test.d.ts +2 -0
  182. package/dist/types/src/plugin-operation/history/history-tracker.test.d.ts.map +1 -0
  183. package/dist/types/src/plugin-operation/history/index.d.ts +6 -0
  184. package/dist/types/src/plugin-operation/history/index.d.ts.map +1 -0
  185. package/dist/types/src/plugin-operation/history/types.d.ts +13 -0
  186. package/dist/types/src/plugin-operation/history/types.d.ts.map +1 -0
  187. package/dist/types/src/plugin-operation/history/undo-mapping.d.ts +101 -0
  188. package/dist/types/src/plugin-operation/history/undo-mapping.d.ts.map +1 -0
  189. package/dist/types/src/plugin-operation/history/undo-registry.d.ts +23 -0
  190. package/dist/types/src/plugin-operation/history/undo-registry.d.ts.map +1 -0
  191. package/dist/types/src/plugin-operation/history/undo-registry.test.d.ts +2 -0
  192. package/dist/types/src/plugin-operation/history/undo-registry.test.d.ts.map +1 -0
  193. package/dist/types/src/plugin-operation/index.d.ts +3 -0
  194. package/dist/types/src/plugin-operation/index.d.ts.map +1 -0
  195. package/dist/types/src/plugin-operation/invoker-capability.d.ts +6 -0
  196. package/dist/types/src/plugin-operation/invoker-capability.d.ts.map +1 -0
  197. package/dist/types/src/plugin-operation/meta.d.ts +3 -0
  198. package/dist/types/src/plugin-operation/meta.d.ts.map +1 -0
  199. package/dist/types/src/plugin-operation/testing.d.ts +59 -0
  200. package/dist/types/src/plugin-operation/testing.d.ts.map +1 -0
  201. package/dist/types/src/plugin-runtime/RuntimePlugin.d.ts +3 -0
  202. package/dist/types/src/plugin-runtime/RuntimePlugin.d.ts.map +1 -0
  203. package/dist/types/src/plugin-runtime/capability.d.ts +6 -0
  204. package/dist/types/src/plugin-runtime/capability.d.ts.map +1 -0
  205. package/dist/types/src/plugin-runtime/index.d.ts +2 -0
  206. package/dist/types/src/plugin-runtime/index.d.ts.map +1 -0
  207. package/dist/types/src/plugin-runtime/meta.d.ts +3 -0
  208. package/dist/types/src/plugin-runtime/meta.d.ts.map +1 -0
  209. package/dist/types/src/testing/harness.d.ts +67 -0
  210. package/dist/types/src/testing/harness.d.ts.map +1 -0
  211. package/dist/types/src/testing/index.d.ts +2 -0
  212. package/dist/types/src/testing/index.d.ts.map +1 -1
  213. package/dist/types/src/testing/react.d.ts +27 -0
  214. package/dist/types/src/testing/react.d.ts.map +1 -0
  215. package/dist/types/src/testing/react.test.d.ts +2 -0
  216. package/dist/types/src/testing/react.test.d.ts.map +1 -0
  217. package/dist/types/src/testing/service.d.ts +8 -0
  218. package/dist/types/src/testing/service.d.ts.map +1 -0
  219. package/dist/types/src/testing/withPluginManager.d.ts +11 -10
  220. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  221. package/dist/types/src/testing/withPluginManager.stories.d.ts +9 -3
  222. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  223. package/dist/types/src/ui/components/App/App.d.ts +9 -0
  224. package/dist/types/src/ui/components/App/App.d.ts.map +1 -0
  225. package/dist/types/src/ui/components/App/App.stories.d.ts +19 -0
  226. package/dist/types/src/ui/components/App/App.stories.d.ts.map +1 -0
  227. package/dist/types/src/ui/components/App/index.d.ts +2 -0
  228. package/dist/types/src/ui/components/App/index.d.ts.map +1 -0
  229. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts +64 -0
  230. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts.map +1 -0
  231. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts +19 -0
  232. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts.map +1 -0
  233. package/dist/types/src/ui/components/Placeholder/index.d.ts +2 -0
  234. package/dist/types/src/ui/components/Placeholder/index.d.ts.map +1 -0
  235. package/dist/types/src/ui/components/PluginManager/PluginManagerContext.stories.d.ts +13 -0
  236. package/dist/types/src/ui/components/PluginManager/PluginManagerContext.stories.d.ts.map +1 -0
  237. package/dist/types/src/ui/components/PluginManager/PluginManagerProvider.d.ts +10 -0
  238. package/dist/types/src/ui/components/PluginManager/PluginManagerProvider.d.ts.map +1 -0
  239. package/dist/types/src/ui/components/PluginManager/index.d.ts +2 -0
  240. package/dist/types/src/ui/components/PluginManager/index.d.ts.map +1 -0
  241. package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts +24 -0
  242. package/dist/types/src/ui/components/Surface/SurfaceComponent.d.ts.map +1 -0
  243. package/dist/types/src/ui/components/Surface/SurfaceComponent.stories.d.ts +14 -0
  244. package/dist/types/src/ui/components/Surface/SurfaceComponent.stories.d.ts.map +1 -0
  245. package/dist/types/src/ui/components/Surface/SurfaceInfo.d.ts +11 -0
  246. package/dist/types/src/ui/components/Surface/SurfaceInfo.d.ts.map +1 -0
  247. package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts +48 -0
  248. package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts.map +1 -0
  249. package/dist/types/src/ui/components/Surface/context.d.ts +5 -0
  250. package/dist/types/src/ui/components/Surface/context.d.ts.map +1 -0
  251. package/dist/types/src/ui/components/Surface/index.d.ts +36 -0
  252. package/dist/types/src/ui/components/Surface/index.d.ts.map +1 -0
  253. package/dist/types/src/ui/components/Surface/types.d.ts +197 -0
  254. package/dist/types/src/ui/components/Surface/types.d.ts.map +1 -0
  255. package/dist/types/src/ui/components/Surface/types.test.d.ts +2 -0
  256. package/dist/types/src/ui/components/Surface/types.test.d.ts.map +1 -0
  257. package/dist/types/src/ui/components/index.d.ts +5 -0
  258. package/dist/types/src/ui/components/index.d.ts.map +1 -0
  259. package/dist/types/src/ui/hooks/index.d.ts +6 -0
  260. package/dist/types/src/ui/hooks/index.d.ts.map +1 -0
  261. package/dist/types/src/ui/hooks/useApp.d.ts +89 -0
  262. package/dist/types/src/ui/hooks/useApp.d.ts.map +1 -0
  263. package/dist/types/src/ui/hooks/useApp.test.d.ts +2 -0
  264. package/dist/types/src/ui/hooks/useApp.test.d.ts.map +1 -0
  265. package/dist/types/src/ui/hooks/useCapabilities.d.ts +31 -0
  266. package/dist/types/src/ui/hooks/useCapabilities.d.ts.map +1 -0
  267. package/dist/types/src/ui/hooks/useLoading.d.ts +18 -0
  268. package/dist/types/src/ui/hooks/useLoading.d.ts.map +1 -0
  269. package/dist/types/src/ui/hooks/useSettingsState.d.ts +10 -0
  270. package/dist/types/src/ui/hooks/useSettingsState.d.ts.map +1 -0
  271. package/dist/types/src/ui/hooks/useSurface.d.ts +3 -0
  272. package/dist/types/src/ui/hooks/useSurface.d.ts.map +1 -0
  273. package/dist/types/src/ui/index.d.ts +3 -0
  274. package/dist/types/src/ui/index.d.ts.map +1 -0
  275. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts +34 -0
  276. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts.map +1 -0
  277. package/dist/types/src/vite-plugin/boot-loader/index.d.ts +2 -0
  278. package/dist/types/src/vite-plugin/boot-loader/index.d.ts.map +1 -0
  279. package/dist/types/src/vite-plugin/boot-loader/loader.d.ts +51 -0
  280. package/dist/types/src/vite-plugin/boot-loader/loader.d.ts.map +1 -0
  281. package/dist/types/src/vite-plugin/composer/index.d.ts +34 -0
  282. package/dist/types/src/vite-plugin/composer/index.d.ts.map +1 -0
  283. package/dist/types/src/vite-plugin/import-map/index.d.ts +28 -0
  284. package/dist/types/src/vite-plugin/import-map/index.d.ts.map +1 -0
  285. package/dist/types/src/vite-plugin/index.d.ts +5 -0
  286. package/dist/types/src/vite-plugin/index.d.ts.map +1 -0
  287. package/dist/types/src/vite-plugin/manifest.d.ts +41 -0
  288. package/dist/types/src/vite-plugin/manifest.d.ts.map +1 -0
  289. package/dist/types/src/vite-plugin/manifest.test.d.ts +2 -0
  290. package/dist/types/src/vite-plugin/manifest.test.d.ts.map +1 -0
  291. package/dist/types/src/vite-plugin/packages.d.ts +13 -0
  292. package/dist/types/src/vite-plugin/packages.d.ts.map +1 -0
  293. package/dist/types/tsconfig.tsbuildinfo +1 -1
  294. package/moon.yml +26 -3
  295. package/package.json +117 -53
  296. package/src/cli/cli.ts +107 -0
  297. package/src/{playground/layout → cli}/index.ts +1 -1
  298. package/src/common/activation-events.ts +44 -0
  299. package/src/{playground/debug/index.ts → common/annotations.ts} +0 -2
  300. package/src/common/capabilities.ts +169 -114
  301. package/src/common/index.ts +4 -8
  302. package/src/common/operations.ts +35 -0
  303. package/src/common/translations.ts +18 -10
  304. package/src/context.ts +9 -0
  305. package/src/core/{events.ts → activation-event.ts} +10 -7
  306. package/src/core/capability-manager.test.ts +151 -0
  307. package/src/core/capability-manager.ts +192 -0
  308. package/src/core/capability.ts +247 -0
  309. package/src/core/edge-registry-plugin-provider.ts +92 -0
  310. package/src/core/index.ts +11 -4
  311. package/src/core/plugin-asset-cache.ts +60 -0
  312. package/src/core/plugin-manager.test.ts +1899 -0
  313. package/src/core/plugin-manager.ts +1685 -0
  314. package/src/core/plugin-manifest.test.ts +75 -0
  315. package/src/core/plugin-manifest.ts +134 -0
  316. package/src/core/plugin.ts +404 -43
  317. package/src/core/registry.ts +163 -0
  318. package/src/core/url-loader.test.ts +221 -0
  319. package/src/core/url-loader.ts +388 -0
  320. package/src/helpers.test.ts +1 -1
  321. package/src/index.ts +3 -4
  322. package/src/plugin-operation/OperationPlugin.ts +24 -0
  323. package/src/plugin-operation/history/capability.ts +36 -0
  324. package/src/plugin-operation/history/errors.ts +7 -0
  325. package/src/plugin-operation/history/history-tracker.test.ts +374 -0
  326. package/src/plugin-operation/history/history-tracker.ts +128 -0
  327. package/src/plugin-operation/history/index.ts +9 -0
  328. package/src/plugin-operation/history/types.ts +17 -0
  329. package/src/plugin-operation/history/undo-mapping.ts +135 -0
  330. package/src/plugin-operation/history/undo-registry.test.ts +72 -0
  331. package/src/plugin-operation/history/undo-registry.ts +54 -0
  332. package/src/plugin-operation/index.ts +6 -0
  333. package/src/plugin-operation/invoker-capability.ts +55 -0
  334. package/src/plugin-operation/meta.ts +12 -0
  335. package/src/plugin-operation/testing.ts +155 -0
  336. package/src/plugin-runtime/RuntimePlugin.ts +19 -0
  337. package/src/plugin-runtime/capability.ts +53 -0
  338. package/src/plugin-runtime/index.ts +5 -0
  339. package/src/plugin-runtime/meta.ts +12 -0
  340. package/src/testing/harness.ts +229 -0
  341. package/src/testing/index.ts +2 -0
  342. package/src/testing/react.test.tsx +48 -0
  343. package/src/testing/react.tsx +113 -0
  344. package/src/testing/service.ts +52 -0
  345. package/src/testing/withPluginManager.stories.tsx +15 -12
  346. package/src/testing/withPluginManager.tsx +78 -54
  347. package/src/ui/components/App/App.stories.tsx +88 -0
  348. package/src/ui/components/App/App.tsx +81 -0
  349. package/src/{playground/logger → ui/components/App}/index.ts +1 -1
  350. package/src/ui/components/Placeholder/Placeholder.stories.tsx +77 -0
  351. package/src/ui/components/Placeholder/Placeholder.tsx +155 -0
  352. package/src/ui/components/Placeholder/index.ts +5 -0
  353. package/src/ui/components/PluginManager/PluginManagerContext.stories.tsx +185 -0
  354. package/src/{react → ui/components/PluginManager}/PluginManagerProvider.ts +3 -3
  355. package/src/ui/components/PluginManager/index.ts +5 -0
  356. package/src/ui/components/Surface/SurfaceComponent.stories.tsx +144 -0
  357. package/src/ui/components/Surface/SurfaceComponent.tsx +303 -0
  358. package/src/ui/components/Surface/SurfaceInfo.tsx +106 -0
  359. package/src/ui/components/Surface/SurfaceProfilerContext.tsx +207 -0
  360. package/src/ui/components/Surface/context.ts +12 -0
  361. package/src/ui/components/Surface/index.ts +54 -0
  362. package/src/ui/components/Surface/types.test.ts +126 -0
  363. package/src/ui/components/Surface/types.ts +269 -0
  364. package/src/ui/components/index.ts +8 -0
  365. package/src/ui/hooks/index.ts +9 -0
  366. package/src/ui/hooks/useApp.test.tsx +159 -0
  367. package/src/ui/hooks/useApp.tsx +424 -0
  368. package/src/ui/hooks/useCapabilities.ts +67 -0
  369. package/src/ui/hooks/useLoading.tsx +76 -0
  370. package/src/ui/hooks/useSettingsState.ts +26 -0
  371. package/src/ui/hooks/useSurface.ts +13 -0
  372. package/src/ui/index.ts +6 -0
  373. package/src/vite-plugin/boot-loader/BootLoader.stories.tsx +270 -0
  374. package/src/vite-plugin/boot-loader/boot-loader.css +320 -0
  375. package/src/vite-plugin/boot-loader/boot-loader.js +325 -0
  376. package/src/vite-plugin/boot-loader/index.ts +5 -0
  377. package/src/vite-plugin/boot-loader/loader.ts +123 -0
  378. package/src/vite-plugin/composer/index.ts +306 -0
  379. package/src/vite-plugin/import-map/index.ts +527 -0
  380. package/src/vite-plugin/index.ts +10 -0
  381. package/src/vite-plugin/manifest.test.ts +46 -0
  382. package/src/vite-plugin/manifest.ts +57 -0
  383. package/src/vite-plugin/packages.ts +187 -0
  384. package/tsconfig.json +25 -23
  385. package/tsconfig.node.json +2 -4
  386. package/typedoc.json +2 -4
  387. package/vitest.config.ts +8 -6
  388. package/.swc/plugins/v7_linux_x86_64_13.0.0/f45bdff002284d9e8f9ef3f0be909de12da36c049cbcf261ac78fc00abb09a2d +0 -0
  389. package/.swc/plugins/v7_linux_x86_64_13.0.0/fce1bdb8e20a094e4af08bad09cc81497ed0e2e7c51223b07d371063cca18429 +0 -0
  390. package/dist/lib/browser/app-graph-builder-LYF7EKNN.mjs +0 -137
  391. package/dist/lib/browser/app-graph-builder-LYF7EKNN.mjs.map +0 -7
  392. package/dist/lib/browser/chunk-FMN65HSW.mjs +0 -1519
  393. package/dist/lib/browser/chunk-FMN65HSW.mjs.map +0 -7
  394. package/dist/lib/browser/chunk-FO2PH7M3.mjs +0 -415
  395. package/dist/lib/browser/chunk-FO2PH7M3.mjs.map +0 -7
  396. package/dist/lib/browser/chunk-ORWHM7CO.mjs +0 -32
  397. package/dist/lib/browser/chunk-ORWHM7CO.mjs.map +0 -7
  398. package/dist/lib/browser/intent-dispatcher-LSYQZSEB.mjs +0 -11
  399. package/dist/lib/browser/intent-resolver-ZTNOSO3A.mjs +0 -39
  400. package/dist/lib/browser/intent-resolver-ZTNOSO3A.mjs.map +0 -7
  401. package/dist/lib/browser/store-KML2R4IE.mjs +0 -30
  402. package/dist/lib/browser/store-KML2R4IE.mjs.map +0 -7
  403. package/dist/lib/browser/worker.mjs +0 -79
  404. package/dist/lib/node-esm/app-graph-builder-SAOWGJDK.mjs +0 -138
  405. package/dist/lib/node-esm/app-graph-builder-SAOWGJDK.mjs.map +0 -7
  406. package/dist/lib/node-esm/chunk-73HGSHKE.mjs +0 -416
  407. package/dist/lib/node-esm/chunk-73HGSHKE.mjs.map +0 -7
  408. package/dist/lib/node-esm/chunk-UMZQERLE.mjs +0 -34
  409. package/dist/lib/node-esm/chunk-UMZQERLE.mjs.map +0 -7
  410. package/dist/lib/node-esm/chunk-ZEZ4FVEU.mjs +0 -1521
  411. package/dist/lib/node-esm/chunk-ZEZ4FVEU.mjs.map +0 -7
  412. package/dist/lib/node-esm/intent-dispatcher-6CYNGPSW.mjs +0 -12
  413. package/dist/lib/node-esm/intent-resolver-W7Z7WFFM.mjs +0 -40
  414. package/dist/lib/node-esm/intent-resolver-W7Z7WFFM.mjs.map +0 -7
  415. package/dist/lib/node-esm/store-QEXGXLWZ.mjs +0 -31
  416. package/dist/lib/node-esm/store-QEXGXLWZ.mjs.map +0 -7
  417. package/dist/lib/node-esm/worker.mjs +0 -80
  418. package/dist/types/src/App.d.ts +0 -43
  419. package/dist/types/src/App.d.ts.map +0 -1
  420. package/dist/types/src/common/collaboration.d.ts +0 -19
  421. package/dist/types/src/common/collaboration.d.ts.map +0 -1
  422. package/dist/types/src/common/events.d.ts +0 -52
  423. package/dist/types/src/common/events.d.ts.map +0 -1
  424. package/dist/types/src/common/file.d.ts +0 -14
  425. package/dist/types/src/common/file.d.ts.map +0 -1
  426. package/dist/types/src/common/graph.d.ts +0 -21
  427. package/dist/types/src/common/graph.d.ts.map +0 -1
  428. package/dist/types/src/common/layout.d.ts +0 -281
  429. package/dist/types/src/common/layout.d.ts.map +0 -1
  430. package/dist/types/src/common/surface.d.ts +0 -65
  431. package/dist/types/src/common/surface.d.ts.map +0 -1
  432. package/dist/types/src/core/capabilities.d.ts +0 -114
  433. package/dist/types/src/core/capabilities.d.ts.map +0 -1
  434. package/dist/types/src/core/capabilities.test.d.ts +0 -2
  435. package/dist/types/src/core/capabilities.test.d.ts.map +0 -1
  436. package/dist/types/src/core/events.d.ts.map +0 -1
  437. package/dist/types/src/core/manager.d.ts +0 -122
  438. package/dist/types/src/core/manager.d.ts.map +0 -1
  439. package/dist/types/src/core/manager.test.d.ts +0 -2
  440. package/dist/types/src/core/manager.test.d.ts.map +0 -1
  441. package/dist/types/src/playground/debug/Debug.d.ts +0 -6
  442. package/dist/types/src/playground/debug/Debug.d.ts.map +0 -1
  443. package/dist/types/src/playground/debug/index.d.ts +0 -2
  444. package/dist/types/src/playground/debug/index.d.ts.map +0 -1
  445. package/dist/types/src/playground/debug/plugin.d.ts +0 -2
  446. package/dist/types/src/playground/debug/plugin.d.ts.map +0 -1
  447. package/dist/types/src/playground/generator/Main.d.ts +0 -6
  448. package/dist/types/src/playground/generator/Main.d.ts.map +0 -1
  449. package/dist/types/src/playground/generator/Toolbar.d.ts +0 -6
  450. package/dist/types/src/playground/generator/Toolbar.d.ts.map +0 -1
  451. package/dist/types/src/playground/generator/generator.d.ts +0 -7
  452. package/dist/types/src/playground/generator/generator.d.ts.map +0 -1
  453. package/dist/types/src/playground/generator/index.d.ts +0 -3
  454. package/dist/types/src/playground/generator/index.d.ts.map +0 -1
  455. package/dist/types/src/playground/generator/plugin.d.ts +0 -2
  456. package/dist/types/src/playground/generator/plugin.d.ts.map +0 -1
  457. package/dist/types/src/playground/layout/Layout.d.ts +0 -8
  458. package/dist/types/src/playground/layout/Layout.d.ts.map +0 -1
  459. package/dist/types/src/playground/layout/index.d.ts +0 -2
  460. package/dist/types/src/playground/layout/index.d.ts.map +0 -1
  461. package/dist/types/src/playground/layout/plugin.d.ts +0 -2
  462. package/dist/types/src/playground/layout/plugin.d.ts.map +0 -1
  463. package/dist/types/src/playground/logger/Toolbar.d.ts +0 -6
  464. package/dist/types/src/playground/logger/Toolbar.d.ts.map +0 -1
  465. package/dist/types/src/playground/logger/index.d.ts +0 -2
  466. package/dist/types/src/playground/logger/index.d.ts.map +0 -1
  467. package/dist/types/src/playground/logger/plugin.d.ts +0 -2
  468. package/dist/types/src/playground/logger/plugin.d.ts.map +0 -1
  469. package/dist/types/src/playground/logger/schema.d.ts +0 -13
  470. package/dist/types/src/playground/logger/schema.d.ts.map +0 -1
  471. package/dist/types/src/playground/playground.stories.d.ts +0 -10
  472. package/dist/types/src/playground/playground.stories.d.ts.map +0 -1
  473. package/dist/types/src/plugin-intent/IntentPlugin.d.ts +0 -2
  474. package/dist/types/src/plugin-intent/IntentPlugin.d.ts.map +0 -1
  475. package/dist/types/src/plugin-intent/actions.d.ts +0 -38
  476. package/dist/types/src/plugin-intent/actions.d.ts.map +0 -1
  477. package/dist/types/src/plugin-intent/errors.d.ts +0 -16
  478. package/dist/types/src/plugin-intent/errors.d.ts.map +0 -1
  479. package/dist/types/src/plugin-intent/index.d.ts +0 -5
  480. package/dist/types/src/plugin-intent/index.d.ts.map +0 -1
  481. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts +0 -139
  482. package/dist/types/src/plugin-intent/intent-dispatcher.d.ts.map +0 -1
  483. package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts +0 -2
  484. package/dist/types/src/plugin-intent/intent-dispatcher.test.d.ts.map +0 -1
  485. package/dist/types/src/plugin-intent/intent.d.ts +0 -63
  486. package/dist/types/src/plugin-intent/intent.d.ts.map +0 -1
  487. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts +0 -2
  488. package/dist/types/src/plugin-settings/SettingsPlugin.d.ts.map +0 -1
  489. package/dist/types/src/plugin-settings/actions.d.ts +0 -27
  490. package/dist/types/src/plugin-settings/actions.d.ts.map +0 -1
  491. package/dist/types/src/plugin-settings/app-graph-builder.d.ts +0 -4
  492. package/dist/types/src/plugin-settings/app-graph-builder.d.ts.map +0 -1
  493. package/dist/types/src/plugin-settings/index.d.ts +0 -3
  494. package/dist/types/src/plugin-settings/index.d.ts.map +0 -1
  495. package/dist/types/src/plugin-settings/intent-resolver.d.ts +0 -4
  496. package/dist/types/src/plugin-settings/intent-resolver.d.ts.map +0 -1
  497. package/dist/types/src/plugin-settings/store.d.ts +0 -5
  498. package/dist/types/src/plugin-settings/store.d.ts.map +0 -1
  499. package/dist/types/src/plugin-settings/translations.d.ts +0 -10
  500. package/dist/types/src/plugin-settings/translations.d.ts.map +0 -1
  501. package/dist/types/src/react/ErrorBoundary.d.ts +0 -31
  502. package/dist/types/src/react/ErrorBoundary.d.ts.map +0 -1
  503. package/dist/types/src/react/IntentContext.d.ts +0 -8
  504. package/dist/types/src/react/IntentContext.d.ts.map +0 -1
  505. package/dist/types/src/react/PluginManagerProvider.d.ts +0 -10
  506. package/dist/types/src/react/PluginManagerProvider.d.ts.map +0 -1
  507. package/dist/types/src/react/Surface.d.ts +0 -12
  508. package/dist/types/src/react/Surface.d.ts.map +0 -1
  509. package/dist/types/src/react/Surface.stories.d.ts +0 -16
  510. package/dist/types/src/react/Surface.stories.d.ts.map +0 -1
  511. package/dist/types/src/react/common.d.ts +0 -13
  512. package/dist/types/src/react/common.d.ts.map +0 -1
  513. package/dist/types/src/react/index.d.ts +0 -7
  514. package/dist/types/src/react/index.d.ts.map +0 -1
  515. package/dist/types/src/react/useCapabilities.d.ts +0 -13
  516. package/dist/types/src/react/useCapabilities.d.ts.map +0 -1
  517. package/dist/types/src/react/useIntentResolver.d.ts +0 -3
  518. package/dist/types/src/react/useIntentResolver.d.ts.map +0 -1
  519. package/dist/types/src/worker.d.ts +0 -4
  520. package/dist/types/src/worker.d.ts.map +0 -1
  521. package/src/App.tsx +0 -276
  522. package/src/common/collaboration.ts +0 -21
  523. package/src/common/events.ts +0 -77
  524. package/src/common/file.ts +0 -22
  525. package/src/common/graph.ts +0 -30
  526. package/src/common/layout.ts +0 -278
  527. package/src/common/surface.ts +0 -86
  528. package/src/core/capabilities.test.ts +0 -136
  529. package/src/core/capabilities.ts +0 -254
  530. package/src/core/manager.test.ts +0 -515
  531. package/src/core/manager.ts +0 -519
  532. package/src/playground/debug/Debug.tsx +0 -39
  533. package/src/playground/debug/plugin.ts +0 -17
  534. package/src/playground/generator/Main.tsx +0 -71
  535. package/src/playground/generator/Toolbar.tsx +0 -46
  536. package/src/playground/generator/generator.ts +0 -48
  537. package/src/playground/generator/index.ts +0 -6
  538. package/src/playground/generator/plugin.ts +0 -23
  539. package/src/playground/layout/Layout.tsx +0 -33
  540. package/src/playground/layout/plugin.ts +0 -17
  541. package/src/playground/logger/Toolbar.tsx +0 -29
  542. package/src/playground/logger/plugin.ts +0 -36
  543. package/src/playground/logger/schema.ts +0 -12
  544. package/src/playground/playground.stories.tsx +0 -42
  545. package/src/plugin-intent/IntentPlugin.ts +0 -20
  546. package/src/plugin-intent/actions.ts +0 -33
  547. package/src/plugin-intent/errors.ts +0 -39
  548. package/src/plugin-intent/index.ts +0 -8
  549. package/src/plugin-intent/intent-dispatcher.test.ts +0 -279
  550. package/src/plugin-intent/intent-dispatcher.ts +0 -333
  551. package/src/plugin-intent/intent.ts +0 -154
  552. package/src/plugin-settings/SettingsPlugin.ts +0 -35
  553. package/src/plugin-settings/actions.ts +0 -29
  554. package/src/plugin-settings/app-graph-builder.ts +0 -157
  555. package/src/plugin-settings/index.ts +0 -6
  556. package/src/plugin-settings/intent-resolver.ts +0 -34
  557. package/src/plugin-settings/store.ts +0 -33
  558. package/src/plugin-settings/translations.ts +0 -19
  559. package/src/react/ErrorBoundary.tsx +0 -45
  560. package/src/react/IntentContext.tsx +0 -34
  561. package/src/react/Surface.stories.tsx +0 -96
  562. package/src/react/Surface.tsx +0 -77
  563. package/src/react/common.ts +0 -12
  564. package/src/react/index.ts +0 -10
  565. package/src/react/useCapabilities.ts +0 -30
  566. package/src/react/useIntentResolver.ts +0 -22
  567. package/src/worker.ts +0 -11
  568. /package/dist/lib/browser/{intent-dispatcher-LSYQZSEB.mjs.map → chunk-J5LGTIGS.mjs.map} +0 -0
  569. /package/dist/lib/browser/{worker.mjs.map → common/activation-events.mjs.map} +0 -0
  570. /package/dist/lib/{node-esm/intent-dispatcher-6CYNGPSW.mjs.map → browser/common/capabilities.mjs.map} +0 -0
  571. /package/dist/lib/{node-esm/worker.mjs.map → browser/core/activation-event.mjs.map} +0 -0
@@ -0,0 +1,1685 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Atom, Registry } from '@effect-atom/atom-react';
6
+ import * as Array from 'effect/Array';
7
+ import * as Cause from 'effect/Cause';
8
+ import * as Deferred from 'effect/Deferred';
9
+ import * as Duration from 'effect/Duration';
10
+ import * as Effect from 'effect/Effect';
11
+ import * as Fiber from 'effect/Fiber';
12
+ import * as Function from 'effect/Function';
13
+ import * as HashSet from 'effect/HashSet';
14
+ import * as PubSub from 'effect/PubSub';
15
+ import * as Ref from 'effect/Ref';
16
+
17
+ import { runAndForwardErrors } from '@dxos/effect';
18
+ import { Performance } from '@dxos/effect';
19
+ import { BaseError } from '@dxos/errors';
20
+ import { log } from '@dxos/log';
21
+
22
+ import * as ActivationEvent from './activation-event';
23
+ import * as Capability from './capability';
24
+ import * as CapabilityManager from './capability-manager';
25
+ import * as Plugin from './plugin';
26
+ // Imported with a `PluginRegistry` alias because the unrelated `@effect-atom/atom-react`
27
+ // `Registry` is already imported above; from outside this file the namespace is
28
+ // re-exported as `Registry` via `./index.ts`.
29
+ import * as PluginRegistry from './registry';
30
+
31
+ /**
32
+ * Tagged error for failures during the constructor-launched core/enabled
33
+ * `enable()` chain. Surfaces via {@link PluginManager.activate}'s wait on
34
+ * `_initialization` so a caller blocked on initialization gets a typed
35
+ * failure (with the original error preserved as `cause`) instead of an
36
+ * untyped `Error`.
37
+ */
38
+ export class PluginInitializationError extends BaseError.extend(
39
+ 'PluginInitializationError',
40
+ 'Plugin manager initialization failed',
41
+ ) {}
42
+
43
+ /**
44
+ * Tagged error raised when a plugin exceeds its configured load or activation
45
+ * timeout. The plugin manager records the failure on the `failed` atom and
46
+ * auto-disables the plugin so that one stuck remote does not stall app boot.
47
+ * `context.id` is the plugin id, `context.phase` is `'load'` or `'activation'`.
48
+ */
49
+ export class PluginTimeoutError extends BaseError.extend('PluginTimeoutError', 'Plugin operation timed out') {}
50
+
51
+ /** Phase of the plugin lifecycle in which the failure was observed. */
52
+ export type PluginFailurePhase = 'load' | 'activation';
53
+
54
+ /** Why the plugin entered a failed state. */
55
+ export type PluginFailureReason = 'timeout' | 'error';
56
+
57
+ /**
58
+ * Record of a plugin that failed to load or activate. Surfaced via the
59
+ * {@link PluginManager.failed} atom so registry / UI consumers can flag
60
+ * unhealthy plugins (e.g. a remote host that has gone offline) rather than
61
+ * leaving the app in a half-broken state.
62
+ */
63
+ export type PluginFailure = {
64
+ readonly id: string;
65
+ readonly phase: PluginFailurePhase;
66
+ readonly reason: PluginFailureReason;
67
+ readonly error: Error;
68
+ /** `Date.now()` when the failure was recorded. */
69
+ readonly timestamp: number;
70
+ };
71
+
72
+ /** Default deadline for resolving a lazy plugin's dynamic import. */
73
+ const DEFAULT_LOAD_TIMEOUT = Duration.seconds(30);
74
+
75
+ /** Default deadline for a single module's `activate()` body. */
76
+ const DEFAULT_ACTIVATION_TIMEOUT = Duration.seconds(30);
77
+
78
+ /**
79
+ * Identifier denoting a Manager.
80
+ */
81
+ export const ManagerTypeId: unique symbol = Symbol.for('@dxos/app-framework/Manager');
82
+ export type ManagerTypeId = typeof ManagerTypeId;
83
+
84
+ /**
85
+ * Loader result that carries optional metadata about how the plugin was sourced.
86
+ *
87
+ * `dev: true` marks a plugin as session-only and triggers shadow-on-id-collision
88
+ * inside the manager: if a plugin with the same id is already registered (a
89
+ * builtin, or a previously-installed plugin from the registry), the dev plugin
90
+ * temporarily takes over that id slot. The original is restored when the dev
91
+ * plugin is removed (or on page reload, since dev plugins aren't persisted).
92
+ */
93
+ export type LoadedPlugin = {
94
+ plugin: Plugin.Plugin;
95
+ /** True when the plugin came from a dev source. See type doc for semantics. */
96
+ dev?: boolean;
97
+ };
98
+
99
+ export type ManagerOptions = {
100
+ pluginLoader: (id: string) => Effect.Effect<LoadedPlugin, Error>;
101
+ plugins?: Plugin.Plugin[];
102
+ core?: string[];
103
+ enabled?: string[];
104
+ registry?: Registry.Registry;
105
+ /**
106
+ * Backend for the plugin registry catalog. When omitted the manager exposes a
107
+ * no-op `pluginRegistry` (empty list, no versions endpoint). Implementations
108
+ * live in app-framework alongside the interface (e.g.
109
+ * `EdgeRegistryPluginProvider`); the host app instantiates one and passes it in.
110
+ */
111
+ pluginRegistryProvider?: PluginRegistry.PluginProvider;
112
+ /**
113
+ * Hook called when a plugin is removed via {@link PluginManager.remove}. Used by the
114
+ * host app to clean up persisted state (e.g. evict offline-cached plugin assets).
115
+ * Failures are logged and swallowed; removal still succeeds even if the hook fails.
116
+ */
117
+ onRemove?: (id: string) => Effect.Effect<void, unknown>;
118
+ /**
119
+ * Maximum time allowed for a lazy plugin's dynamic `import()` to resolve.
120
+ * Plugins that exceed this are flagged on the {@link PluginManager.failed}
121
+ * atom and auto-disabled so a stuck remote host can't stall app boot.
122
+ * Defaults to 30 seconds; pass `Duration.infinity` to disable.
123
+ */
124
+ loadTimeout?: Duration.DurationInput;
125
+ /**
126
+ * Maximum time allowed for a single module's `activate()` Effect to settle.
127
+ * Modules that exceed this fail with {@link PluginTimeoutError}; the owning
128
+ * plugin is recorded on `failed` and auto-disabled. Defaults to 30 seconds;
129
+ * pass `Duration.infinity` to disable.
130
+ */
131
+ activationTimeout?: Duration.DurationInput;
132
+ };
133
+
134
+ export type ActivationMessage = {
135
+ event: string;
136
+ state: 'activating' | 'activated' | 'error';
137
+ /** Module ID when the message pertains to a specific module activation. */
138
+ module?: string;
139
+ error?: Error;
140
+ };
141
+
142
+ /**
143
+ * Interface for the Plugin Manager.
144
+ */
145
+ export interface PluginManager {
146
+ readonly [ManagerTypeId]: ManagerTypeId;
147
+ readonly activation: PubSub.PubSub<ActivationMessage>;
148
+ readonly capabilities: CapabilityManager.CapabilityManager;
149
+ readonly registry: Registry.Registry;
150
+ /**
151
+ * Cached registry catalog state plus pass-throughs for `listVersions` /
152
+ * `getPlugin`. Always present — the host supplies a `pluginRegistryProvider`
153
+ * via {@link ManagerOptions} for real backends, or it falls back to a no-op
154
+ * implementation that yields an empty catalog.
155
+ */
156
+ readonly pluginRegistry: PluginRegistry.Manager;
157
+
158
+ readonly plugins: Atom.Atom<readonly Plugin.Plugin[]>;
159
+ readonly core: Atom.Atom<readonly string[]>;
160
+ readonly enabled: Atom.Atom<readonly string[]>;
161
+ readonly modules: Atom.Atom<readonly Plugin.PluginModule[]>;
162
+ readonly active: Atom.Atom<readonly string[]>;
163
+ readonly eventsFired: Atom.Atom<readonly string[]>;
164
+ readonly pendingReset: Atom.Atom<readonly string[]>;
165
+ /**
166
+ * Plugins that failed to load or activate. Subscribers (e.g. the registry
167
+ * UI) can use this to flag unhealthy entries; a plugin id appears here at
168
+ * most once with its most recent failure.
169
+ */
170
+ readonly failed: Atom.Atom<readonly PluginFailure[]>;
171
+ /**
172
+ * Ids of currently-registered plugins that came from a dev source (loaded
173
+ * via {@link LoadedPlugin} with `dev: true`). Subscribers can use this to
174
+ * badge dev-overridden plugins or to derive the id of the active dev plugin
175
+ * for an "uninstall dev plugin" affordance.
176
+ */
177
+ readonly devPluginIds: Atom.Atom<readonly string[]>;
178
+
179
+ getPlugins(): readonly Plugin.Plugin[];
180
+ getCore(): readonly string[];
181
+ getEnabled(): readonly string[];
182
+ getModules(): readonly Plugin.PluginModule[];
183
+ getActive(): readonly string[];
184
+ getEventsFired(): readonly string[];
185
+ getPendingReset(): readonly string[];
186
+ getFailed(): readonly PluginFailure[];
187
+ getDevPluginIds(): readonly string[];
188
+
189
+ /**
190
+ * Clears the failure record for a plugin so it can be retried. Returns
191
+ * whether a failure record existed and was removed.
192
+ */
193
+ clearFailure(id: string): boolean;
194
+
195
+ /**
196
+ * Loads a plugin via the plugin loader and registers it without enabling it.
197
+ * Returns the loaded plugin so callers can enable it by its canonical id
198
+ * (which may differ from the locator used to load it, e.g. URL loaders).
199
+ */
200
+ add(id: string): Effect.Effect<Plugin.Plugin, Error>;
201
+
202
+ /**
203
+ * Enables a plugin.
204
+ *
205
+ * Default behavior auto-resolves the plugin's declared `dependsOn` closure:
206
+ * missing entries that exist in the plugin registry catalog are installed via
207
+ * {@link add}, then enabled in dependency-first order. Set `resolveDependencies`
208
+ * to `false` to enable only the named plugin and skip the closure walk
209
+ * entirely — useful when substituting an alternative plugin that satisfies
210
+ * the dependent's capability needs in its own way.
211
+ */
212
+ enable(id: string, opts?: { resolveDependencies?: boolean }): Effect.Effect<boolean, Error>;
213
+
214
+ /**
215
+ * Removes a plugin from the manager (disables then unregisters).
216
+ *
217
+ * Honors the same cascade option as {@link disable}.
218
+ */
219
+ remove(id: string, opts?: { cascade?: boolean }): Effect.Effect<boolean, Error>;
220
+
221
+ /**
222
+ * Disables a plugin.
223
+ *
224
+ * By default, cascades to currently-enabled dependents (transitively, leaves
225
+ * first) so disabling a depended-upon plugin never leaves its dependents
226
+ * stranded. Pass `cascade: false` to disable only the named plugin and leave
227
+ * its dependents enabled-but-broken — VS Code-style disable parity for
228
+ * callers that want the escape hatch (e.g. when swapping in an alternative
229
+ * implementation that satisfies the dependents' needs in its own way).
230
+ *
231
+ * Fails with {@link Plugin.PluginDependencyError} (`reason: 'core-dependent'`)
232
+ * when cascading would require disabling a core plugin; UI flows should
233
+ * surface their own confirmation before calling `disable` with the default.
234
+ */
235
+ disable(id: string, opts?: { cascade?: boolean }): Effect.Effect<boolean, Error>;
236
+
237
+ /**
238
+ * Returns the plugin ids that the given plugin declares as dependencies.
239
+ *
240
+ * Walks `meta.dependsOn` from both registered plugins and the plugin registry
241
+ * catalog so callers can preview the closure for a plugin that isn't yet
242
+ * installed. With `transitive: true` (default), returns the full dependency
243
+ * closure in dependency-first order (deps before dependents). Without it,
244
+ * returns the direct declarations only.
245
+ */
246
+ getDependencies(id: string, opts?: { transitive?: boolean }): readonly string[];
247
+
248
+ /**
249
+ * Returns the plugin ids that declare the given plugin as a dependency.
250
+ *
251
+ * Walks `meta.dependsOn` over registered plugins. With `transitive: true`
252
+ * (default), returns the full reverse closure. With `enabledOnly: true`,
253
+ * filters to currently-enabled dependents — used by UI flows to preview what
254
+ * a cascading disable would touch.
255
+ */
256
+ getDependents(id: string, opts?: { transitive?: boolean; enabledOnly?: boolean }): readonly string[];
257
+ // TODO(wittjosiah): Improve error typing.
258
+ activate(
259
+ event: ActivationEvent.ActivationEvent | string,
260
+ params?: { before?: string; after?: string },
261
+ ): Effect.Effect<boolean, Error>;
262
+ deactivate(id: string): Effect.Effect<boolean, Error>;
263
+ reset(event: ActivationEvent.ActivationEvent | string): Effect.Effect<boolean, Error>;
264
+
265
+ /**
266
+ * Shuts down the manager by deactivating all active modules in reverse activation order,
267
+ * clearing all capabilities, and resetting lifecycle bookkeeping.
268
+ * Plugins, core, enabled, and modules remain intact so the manager can be reused.
269
+ */
270
+ shutdown(): Effect.Effect<boolean, Error>;
271
+ }
272
+
273
+ /**
274
+ * Type guard to check if a value is a PluginManager.
275
+ */
276
+ export const isManager = (value: unknown): value is PluginManager => {
277
+ return typeof value === 'object' && value !== null && ManagerTypeId in value;
278
+ };
279
+
280
+ /**
281
+ * Internal implementation of PluginManager.
282
+ */
283
+ class ManagerImpl implements PluginManager {
284
+ readonly [ManagerTypeId]: ManagerTypeId = ManagerTypeId;
285
+ readonly activation = Effect.runSync(PubSub.unbounded<ActivationMessage>());
286
+ readonly capabilities: CapabilityManager.CapabilityManager;
287
+ readonly registry: Registry.Registry;
288
+ readonly pluginRegistry: PluginRegistry.Manager;
289
+
290
+ private readonly _pluginsAtom: Atom.Writable<Plugin.Plugin[]>;
291
+ private readonly _coreAtom: Atom.Writable<string[]>;
292
+ private readonly _enabledAtom: Atom.Writable<string[]>;
293
+ private readonly _modulesAtom: Atom.Writable<Plugin.PluginModule[]>;
294
+ private readonly _activeAtom: Atom.Writable<string[]>;
295
+ private readonly _eventsFiredAtom: Atom.Writable<string[]>;
296
+ private readonly _pendingResetAtom: Atom.Writable<string[]>;
297
+ private readonly _failedAtom: Atom.Writable<PluginFailure[]>;
298
+ private readonly _pluginLoader: ManagerOptions['pluginLoader'];
299
+ private readonly _onRemove: ManagerOptions['onRemove'];
300
+ private readonly _loadTimeout: Duration.DurationInput;
301
+ private readonly _activationTimeout: Duration.DurationInput;
302
+ private readonly _capabilities = new Map<string, Capability.Any[]>();
303
+ private readonly _moduleMemoMap = new Map<Plugin.PluginModule['id'], Deferred.Deferred<Capability.Any[], Error>>();
304
+ private readonly _moduleSemaphores = new Map<Plugin.PluginModule['id'], Effect.Semaphore>();
305
+ // Coalesces concurrent `_resolveLazyPlugin` calls per plugin id. Without
306
+ // this, two callers entering `enable(id)` before the swap completes would
307
+ // each invoke `mod.default(options)` and produce distinct module objects,
308
+ // defeating `_addModule`'s reference-equality dedupe and racing the
309
+ // `_pluginsAtom` swap.
310
+ private readonly _resolvingPlugins = new Map<string, Deferred.Deferred<Plugin.Plugin, Plugin.LazyPluginError>>();
311
+ // Tracks dev-source plugins (loaded via a Vite dev server) keyed by id.
312
+ // When `shadow` is present, the entry has displaced an existing plugin —
313
+ // `remove` reinstates it and re-enables iff `wasEnabled`. Entries without a
314
+ // shadow are dev plugins with no underlying registry/builtin to restore.
315
+ // The atom mirrors the map's keys for UI subscribers (they don't need the
316
+ // shadow internals); the two stay in sync via {@link _markDev}/{@link _unmarkDev}.
317
+ private readonly _devPlugins = new Map<string, { shadow?: { plugin: Plugin.Plugin; wasEnabled: boolean } }>();
318
+ private readonly _devPluginIdsAtom: Atom.Writable<string[]>;
319
+ private readonly _activatingEvents = Effect.runSync(Ref.make<string[]>([]));
320
+ private readonly _activatingModules = Effect.runSync(Ref.make<string[]>([]));
321
+ private readonly _inFlightFibers = Effect.runSync(Ref.make<Array<Fiber.Fiber<unknown, unknown>>>([]));
322
+ private readonly _shutdownSemaphore = Effect.runSync(Effect.makeSemaphore(1));
323
+ private readonly _shuttingDown = Effect.runSync(Ref.make(false));
324
+ // Tracks the constructor-launched core/enabled `enable()` calls so that
325
+ // `activate` can wait for module registration before dispatching events.
326
+ // Lazy plugins make `enable` asynchronous (a dynamic `import()` happens
327
+ // inside it), so without this synchronization an `activate` triggered
328
+ // immediately after `make` could fire on an empty module set. Failures
329
+ // are wrapped in `PluginInitializationError` so awaiters get a tagged
330
+ // error rather than the wide `Error` produced by the underlying chain.
331
+ private readonly _initialization = Effect.runSync(Deferred.make<void, PluginInitializationError>());
332
+
333
+ constructor({
334
+ pluginLoader,
335
+ plugins = [],
336
+ core = plugins.map(({ meta }) => meta.id),
337
+ enabled = [],
338
+ registry,
339
+ pluginRegistryProvider,
340
+ onRemove,
341
+ loadTimeout = DEFAULT_LOAD_TIMEOUT,
342
+ activationTimeout = DEFAULT_ACTIVATION_TIMEOUT,
343
+ }: ManagerOptions) {
344
+ this.registry = registry ?? Registry.make();
345
+ this.capabilities = CapabilityManager.make({
346
+ registry: this.registry,
347
+ });
348
+ this.pluginRegistry = new PluginRegistry.Manager(pluginRegistryProvider, this.registry);
349
+
350
+ this._pluginLoader = pluginLoader;
351
+ this._onRemove = onRemove;
352
+ this._loadTimeout = loadTimeout;
353
+ this._activationTimeout = activationTimeout;
354
+ this._pluginsAtom = Atom.make(plugins).pipe(Atom.keepAlive);
355
+ this._coreAtom = Atom.make(core).pipe(Atom.keepAlive);
356
+ this._enabledAtom = Atom.make(enabled).pipe(Atom.keepAlive);
357
+ this._modulesAtom = Atom.make<Plugin.PluginModule[]>([]).pipe(Atom.keepAlive);
358
+ this._activeAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);
359
+ this._eventsFiredAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);
360
+ this._pendingResetAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);
361
+ this._failedAtom = Atom.make<PluginFailure[]>([]).pipe(Atom.keepAlive);
362
+ this._devPluginIdsAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);
363
+ plugins.forEach((plugin) => this._addPlugin(plugin));
364
+ // Dedupe before mapping to `enable` — `core` and `enabled` may overlap (an
365
+ // app-supplied plugin can be in both), and concurrent `enable(id)` calls
366
+ // for the same id are not idempotent (each would re-run the lazy resolve
367
+ // and double-register modules). `new Set([...])` preserves first-seen
368
+ // order which matches the natural core-before-enabled precedence.
369
+ const initialIds = [...new Set([...core, ...enabled])];
370
+ void Effect.all(initialIds.map((id) => this.enable(id)))
371
+ .pipe(
372
+ Effect.mapError((cause) => new PluginInitializationError({ cause })),
373
+ Effect.tap(() => Deferred.succeed(this._initialization, undefined)),
374
+ Effect.tapErrorCause((cause) => Deferred.failCause(this._initialization, cause)),
375
+ )
376
+ .pipe(runAndForwardErrors);
377
+ }
378
+
379
+ get plugins(): Atom.Atom<readonly Plugin.Plugin[]> {
380
+ return this._pluginsAtom;
381
+ }
382
+
383
+ get core(): Atom.Atom<readonly string[]> {
384
+ return this._coreAtom;
385
+ }
386
+
387
+ /**
388
+ * Ids of plugins that are currently enabled.
389
+ */
390
+ get enabled(): Atom.Atom<readonly string[]> {
391
+ return this._enabledAtom;
392
+ }
393
+
394
+ /**
395
+ * Modules of plugins which are currently enabled.
396
+ */
397
+ get modules(): Atom.Atom<readonly Plugin.PluginModule[]> {
398
+ return this._modulesAtom;
399
+ }
400
+
401
+ /**
402
+ * Ids of modules which are currently active.
403
+ */
404
+ get active(): Atom.Atom<readonly string[]> {
405
+ return this._activeAtom;
406
+ }
407
+
408
+ /**
409
+ * Ids of events which have been fired.
410
+ */
411
+ get eventsFired(): Atom.Atom<readonly string[]> {
412
+ return this._eventsFiredAtom;
413
+ }
414
+
415
+ /**
416
+ * Ids of modules which are pending reset.
417
+ */
418
+ get pendingReset(): Atom.Atom<readonly string[]> {
419
+ return this._pendingResetAtom;
420
+ }
421
+
422
+ /**
423
+ * Plugins that failed to load or activate.
424
+ */
425
+ get failed(): Atom.Atom<readonly PluginFailure[]> {
426
+ return this._failedAtom;
427
+ }
428
+
429
+ /**
430
+ * Ids of currently-registered plugins that came from a dev source.
431
+ */
432
+ get devPluginIds(): Atom.Atom<readonly string[]> {
433
+ return this._devPluginIdsAtom;
434
+ }
435
+
436
+ getPlugins(): readonly Plugin.Plugin[] {
437
+ return this._get(this._pluginsAtom);
438
+ }
439
+
440
+ getCore(): readonly string[] {
441
+ return this._get(this._coreAtom);
442
+ }
443
+
444
+ getEnabled(): readonly string[] {
445
+ return this._get(this._enabledAtom);
446
+ }
447
+
448
+ getModules(): readonly Plugin.PluginModule[] {
449
+ return this._get(this._modulesAtom);
450
+ }
451
+
452
+ getActive(): readonly string[] {
453
+ return this._get(this._activeAtom);
454
+ }
455
+
456
+ getEventsFired(): readonly string[] {
457
+ return this._get(this._eventsFiredAtom);
458
+ }
459
+
460
+ getPendingReset(): readonly string[] {
461
+ return this._get(this._pendingResetAtom);
462
+ }
463
+
464
+ getFailed(): readonly PluginFailure[] {
465
+ return this._get(this._failedAtom);
466
+ }
467
+
468
+ getDevPluginIds(): readonly string[] {
469
+ return this._get(this._devPluginIdsAtom);
470
+ }
471
+
472
+ /**
473
+ * Marks `id` as dev-sourced. If the plugin displaced an existing one, pass
474
+ * the shadow snapshot so `remove` can restore it. Repeat calls (e.g. a dev
475
+ * plugin reload) preserve the original shadow target — restoration always
476
+ * unwinds back to the real underlying plugin, never an intermediate dev build.
477
+ */
478
+ private _markDev(id: string, shadow?: { plugin: Plugin.Plugin; wasEnabled: boolean }): void {
479
+ if (this._devPlugins.has(id)) {
480
+ return;
481
+ }
482
+ this._devPlugins.set(id, { shadow });
483
+ this._update(this._devPluginIdsAtom, (ids) => (ids.includes(id) ? ids : [...ids, id]));
484
+ }
485
+
486
+ /** Drops the dev-plugin entry and returns its shadow data (if any) for restoration. */
487
+ private _unmarkDev(id: string): { plugin: Plugin.Plugin; wasEnabled: boolean } | undefined {
488
+ const entry = this._devPlugins.get(id);
489
+ this._devPlugins.delete(id);
490
+ this._update(this._devPluginIdsAtom, (ids) => ids.filter((existing) => existing !== id));
491
+ return entry?.shadow;
492
+ }
493
+
494
+ getDependencies(id: string, opts?: { transitive?: boolean }): readonly string[] {
495
+ const transitive = opts?.transitive !== false;
496
+ if (!transitive) {
497
+ return this._directDependencies(id);
498
+ }
499
+ const walk = this._computeDependencyClosure(id);
500
+ // Drop the target itself; callers asked for its dependencies, not the
501
+ // closure including the root.
502
+ return walk.order.filter((depId) => depId !== id);
503
+ }
504
+
505
+ getDependents(id: string, opts?: { transitive?: boolean; enabledOnly?: boolean }): readonly string[] {
506
+ return this._collectDependents(id, {
507
+ transitive: opts?.transitive !== false,
508
+ enabledOnly: opts?.enabledOnly === true,
509
+ });
510
+ }
511
+
512
+ clearFailure(id: string): boolean {
513
+ const current = this._get(this._failedAtom);
514
+ if (!current.some((failure) => failure.id === id)) {
515
+ return false;
516
+ }
517
+ this._set(
518
+ this._failedAtom,
519
+ current.filter((failure) => failure.id !== id),
520
+ );
521
+ return true;
522
+ }
523
+
524
+ /**
525
+ * Adds a plugin to the manager via the plugin loader.
526
+ * The plugin is registered but not enabled; call `enable` separately to activate it.
527
+ * @param id The id of the plugin.
528
+ */
529
+ add(id: string): Effect.Effect<Plugin.Plugin, Error> {
530
+ return Effect.gen(this, function* () {
531
+ log('add plugin', { id });
532
+ const { plugin, dev = false } = yield* this._pluginLoader(id);
533
+ const pluginId = plugin.meta.id;
534
+ const existing = this._getPlugin(pluginId);
535
+
536
+ if (dev && existing && existing !== plugin) {
537
+ // Shadow path: a plugin with this id is already registered (a builtin,
538
+ // a registry install, or a previous dev load). Disable it, stash it,
539
+ // and swap the dev plugin into the same id slot. The dialog will call
540
+ // `enable(pluginId)` next, which activates the dev plugin's modules.
541
+ // `_markDev` is a no-op when the id is already tracked, so a dev-plugin
542
+ // reload (after editing source) keeps the *original* shadow target —
543
+ // removal restores the real underlying plugin, not an intermediate build.
544
+ const wasEnabled = this._get(this._enabledAtom).includes(pluginId);
545
+ if (wasEnabled) {
546
+ yield* this.disable(pluginId);
547
+ }
548
+ this._markDev(pluginId, { plugin: existing, wasEnabled });
549
+ this._update(this._pluginsAtom, (plugins) => plugins.map((p) => (p.meta.id === pluginId ? plugin : p)));
550
+ } else {
551
+ this._addPlugin(plugin);
552
+ if (dev) {
553
+ this._markDev(pluginId);
554
+ }
555
+ }
556
+
557
+ return plugin;
558
+ });
559
+ }
560
+
561
+ /**
562
+ * Enables a plugin.
563
+ * @param id The id of the plugin.
564
+ * @param opts See {@link PluginManager.enable}.
565
+ */
566
+ enable(id: string, opts?: { resolveDependencies?: boolean }): Effect.Effect<boolean, Error> {
567
+ const resolveDependencies = opts?.resolveDependencies !== false;
568
+ return Effect.gen(this, function* () {
569
+ log('enable plugin', { id, resolveDependencies });
570
+
571
+ if (!resolveDependencies) {
572
+ return yield* this._enableOne(id);
573
+ }
574
+
575
+ // If the root id is unknown to both the registered set and the catalog,
576
+ // fall back to the silent `_enableOne` path (which returns `false`).
577
+ // This preserves the prior contract for persisted `enabled` entries
578
+ // whose plugins are no longer bundled, instead of recording a confusing
579
+ // "missing self-dependency" failure.
580
+ if (!this._getPlugin(id) && !this._getCatalogEntry(id)) {
581
+ return yield* this._enableOne(id);
582
+ }
583
+
584
+ // Compute the transitive closure across registered plugins and catalog
585
+ // entries. Missing or cyclic entries are recorded as failures and the
586
+ // target plugin is left disabled.
587
+ const walk = this._computeDependencyClosure(id);
588
+ if (walk.cycle) {
589
+ this._recordFailure(
590
+ id,
591
+ 'load',
592
+ new Plugin.PluginDependencyError({ context: { id, reason: 'cycle', path: walk.cycle } }),
593
+ );
594
+ return false;
595
+ }
596
+ if (walk.missing.length > 0) {
597
+ this._recordFailure(
598
+ id,
599
+ 'load',
600
+ new Plugin.PluginDependencyError({ context: { id, reason: 'missing', missing: walk.missing } }),
601
+ );
602
+ return false;
603
+ }
604
+
605
+ // Install any catalog-only entries before enabling them. `add` may also
606
+ // discover further declared deps once the plugin's real meta is loaded;
607
+ // we re-walk after each install to absorb those.
608
+ let queue = walk.toInstall.slice();
609
+ const installed = new Set<string>();
610
+ while (queue.length > 0) {
611
+ const next = queue.shift()!;
612
+ if (installed.has(next) || this._getPlugin(next)) {
613
+ continue;
614
+ }
615
+ const installResult = yield* this.add(next).pipe(Effect.either);
616
+ if (installResult._tag === 'Left') {
617
+ this._recordFailure(
618
+ id,
619
+ 'load',
620
+ new Plugin.PluginDependencyError({
621
+ context: { id, reason: 'install-failed', dependency: next },
622
+ cause: installResult.left,
623
+ }),
624
+ );
625
+ return false;
626
+ }
627
+ installed.add(next);
628
+ const rewalk = this._computeDependencyClosure(id);
629
+ if (rewalk.cycle) {
630
+ this._recordFailure(
631
+ id,
632
+ 'load',
633
+ new Plugin.PluginDependencyError({ context: { id, reason: 'cycle', path: rewalk.cycle } }),
634
+ );
635
+ return false;
636
+ }
637
+ if (rewalk.missing.length > 0) {
638
+ this._recordFailure(
639
+ id,
640
+ 'load',
641
+ new Plugin.PluginDependencyError({ context: { id, reason: 'missing', missing: rewalk.missing } }),
642
+ );
643
+ return false;
644
+ }
645
+ queue = rewalk.toInstall.filter((depId) => !installed.has(depId));
646
+ }
647
+
648
+ // Enable in dependency-first order. `_enableOne` is idempotent on the
649
+ // enabled atom so previously-enabled deps short-circuit.
650
+ const order = this._computeDependencyClosure(id).order;
651
+ let succeeded = false;
652
+ for (const depId of order) {
653
+ const ok = yield* this._enableOne(depId);
654
+ if (depId === id) {
655
+ succeeded = ok;
656
+ }
657
+ }
658
+ return succeeded;
659
+ });
660
+ }
661
+
662
+ /**
663
+ * Enables a single plugin without consulting its declared dependencies.
664
+ * Used by {@link enable} as the leaf step after closure resolution, and
665
+ * directly when callers pass `{ resolveDependencies: false }`.
666
+ *
667
+ * The underlying operations (`_addModule`, `_setPendingResetByModule`,
668
+ * `activate`) are all idempotent, so this method is safe to call multiple
669
+ * times for the same id. The constructor's bootstrap path relies on this:
670
+ * the persisted `enabled` ids are written into `_enabledAtom` up front, so
671
+ * the very first `enable(id)` for those plugins sees `alreadyEnabled`-style
672
+ * state but still needs to perform the module registration and activation.
673
+ */
674
+ private _enableOne(id: string): Effect.Effect<boolean, Error> {
675
+ return Effect.gen(this, function* () {
676
+ const stub = this._getPlugin(id);
677
+ if (!stub) {
678
+ return false;
679
+ }
680
+
681
+ // Clear any prior failure record so a retry starts from a clean slate.
682
+ // The failure stays on the atom only if this attempt also fails.
683
+ this.clearFailure(id);
684
+
685
+ const plugin = yield* this._resolveLazyPlugin(stub);
686
+
687
+ this._update(this._enabledAtom, (enabled) => (enabled.includes(id) ? enabled : [...enabled, id]));
688
+
689
+ plugin.modules.forEach((module) => {
690
+ this._addModule(module);
691
+ this._setPendingResetByModule(module);
692
+ });
693
+
694
+ log('pending reset', { events: [...this.getPendingReset()] });
695
+ yield* Effect.all(
696
+ this.getPendingReset().map((event) => this.activate(event)),
697
+ { concurrency: 'unbounded' },
698
+ );
699
+
700
+ return true;
701
+ });
702
+ }
703
+
704
+ /**
705
+ * Resolves a lazy plugin stub (returned by {@link Plugin.lazy}) to its
706
+ * loaded form and swaps it into `_pluginsAtom`. Returns the input unchanged
707
+ * when the plugin is already resolved, so callers can `yield*` this
708
+ * unconditionally. The lazy stub carries `meta` synchronously but its
709
+ * `modules` list is empty until the loader resolves; the swap ensures
710
+ * subsequent enable/disable operations see the resolved plugin.
711
+ *
712
+ * Concurrent calls for the same id are coalesced via `_resolvingPlugins`:
713
+ * the first caller starts the resolution, every subsequent caller awaits
714
+ * the same `Deferred`. On failure we publish a `lazy:<id>` error message
715
+ * and skip the atom swap so the failure is observable to the activation
716
+ * subscriber and a retry can be attempted.
717
+ */
718
+ private _resolveLazyPlugin(plugin: Plugin.Plugin): Effect.Effect<Plugin.Plugin, Plugin.LazyPluginError> {
719
+ return Effect.gen(this, function* () {
720
+ if (!Plugin.isLazy(plugin)) {
721
+ return plugin;
722
+ }
723
+ const id = plugin.meta.id;
724
+
725
+ const existing = this._resolvingPlugins.get(id);
726
+ if (existing) {
727
+ return yield* Deferred.await(existing);
728
+ }
729
+ const deferred = yield* Deferred.make<Plugin.Plugin, Plugin.LazyPluginError>();
730
+ this._resolvingPlugins.set(id, deferred);
731
+
732
+ return yield* Effect.gen(this, function* () {
733
+ log('resolving lazy plugin', { id });
734
+ yield* PubSub.publish(this.activation, { event: '', state: 'activating', module: `lazy:${id}` });
735
+ const resolvedPlugin = yield* Plugin.resolveLazy(plugin).pipe(
736
+ // Cap how long a remote import can hang. Without this the host can
737
+ // sit on a pending dynamic `import()` indefinitely if the plugin's
738
+ // server is unreachable, which stalls every caller awaiting
739
+ // `enable(id)` and (transitively) the manager's initialization.
740
+ Effect.timeoutFail({
741
+ duration: this._loadTimeout,
742
+ onTimeout: () =>
743
+ new Plugin.LazyPluginError({
744
+ context: { id, reason: 'load-failed' },
745
+ cause: new PluginTimeoutError({ context: { id, phase: 'load' as PluginFailurePhase } }),
746
+ }),
747
+ }),
748
+ );
749
+ this._update(this._pluginsAtom, (plugins) => plugins.map((p) => (p.meta.id === id ? resolvedPlugin : p)));
750
+ yield* PubSub.publish(this.activation, { event: '', state: 'activated', module: `lazy:${id}` });
751
+ return resolvedPlugin;
752
+ }).pipe(
753
+ Effect.tapError((error) =>
754
+ Effect.gen(this, function* () {
755
+ yield* PubSub.publish(this.activation, { event: '', state: 'error', module: `lazy:${id}`, error });
756
+ this._recordFailure(id, 'load', error);
757
+ this._scheduleAutoDisable(id);
758
+ }),
759
+ ),
760
+ Effect.tap((value) => Deferred.succeed(deferred, value)),
761
+ Effect.tapErrorCause((cause) => Deferred.failCause(deferred, cause)),
762
+ Effect.ensuring(Effect.sync(() => this._resolvingPlugins.delete(id))),
763
+ );
764
+ });
765
+ }
766
+
767
+ /**
768
+ * Removes a plugin from the manager.
769
+ * @param id The id of the plugin.
770
+ * @param opts See {@link PluginManager.remove}.
771
+ */
772
+ remove(id: string, opts?: { cascade?: boolean }): Effect.Effect<boolean, Error> {
773
+ return Effect.gen(this, function* () {
774
+ log('remove plugin', { id });
775
+ const wasDev = this._devPlugins.has(id);
776
+ const disabled = yield* this.disable(id, opts);
777
+ if (!disabled) {
778
+ return false;
779
+ }
780
+
781
+ this._removePlugin(id);
782
+ if (this._onRemove) {
783
+ this._runForkedFiber(
784
+ this._onRemove(id).pipe(
785
+ Effect.tapError((error) => Effect.sync(() => log.warn('plugin remove hook failed', { id, error }))),
786
+ Effect.ignore,
787
+ ),
788
+ );
789
+ }
790
+
791
+ // If a dev plugin was shadowing an existing plugin, reinstate the
792
+ // original now that the dev plugin is gone. Re-enable only if the
793
+ // original was enabled at shadow time — preserving the user's intent
794
+ // for plugins they had explicitly disabled before iterating on a dev
795
+ // build.
796
+ if (wasDev) {
797
+ const shadow = this._unmarkDev(id);
798
+ if (shadow) {
799
+ this._addPlugin(shadow.plugin);
800
+ if (shadow.wasEnabled) {
801
+ yield* this.enable(id);
802
+ }
803
+ }
804
+ }
805
+ return true;
806
+ });
807
+ }
808
+
809
+ /**
810
+ * Disables a plugin.
811
+ * @param id The id of the plugin.
812
+ * @param opts See {@link PluginManager.disable}.
813
+ */
814
+ disable(id: string, { cascade = true }: { cascade?: boolean } = {}): Effect.Effect<boolean, Error> {
815
+ return Effect.gen(this, function* () {
816
+ log('disable plugin', { id, cascade });
817
+ if (this._get(this._coreAtom).includes(id)) {
818
+ return false;
819
+ }
820
+
821
+ const plugin = this._getPlugin(id);
822
+ if (!plugin) {
823
+ return false;
824
+ }
825
+
826
+ if (cascade) {
827
+ const enabledDependents = this._collectDependents(id, { transitive: true, enabledOnly: true });
828
+ if (enabledDependents.length > 0) {
829
+ const coreDependent = enabledDependents.find((dependentId) =>
830
+ this._get(this._coreAtom).includes(dependentId),
831
+ );
832
+ if (coreDependent) {
833
+ return yield* Effect.fail(
834
+ new Plugin.PluginDependencyError({
835
+ context: { id, reason: 'core-dependent', coreDependent },
836
+ }),
837
+ );
838
+ }
839
+ // Disable transitive dependents first (leaves before root). The
840
+ // walk returns them in dependents-before-deps order — exactly what
841
+ // we want for teardown.
842
+ for (const dependentId of enabledDependents) {
843
+ yield* this._disableOne(dependentId);
844
+ }
845
+ }
846
+ }
847
+
848
+ yield* this._disableOne(id);
849
+ return true;
850
+ });
851
+ }
852
+
853
+ /**
854
+ * Disables a single plugin without consulting its dependents. Used by
855
+ * {@link disable} after the dependents pass has run (or been skipped via
856
+ * `cascade: false`).
857
+ */
858
+ private _disableOne(id: string): Effect.Effect<boolean, Error> {
859
+ return Effect.gen(this, function* () {
860
+ if (this._get(this._coreAtom).includes(id)) {
861
+ return false;
862
+ }
863
+ const plugin = this._getPlugin(id);
864
+ if (!plugin) {
865
+ return false;
866
+ }
867
+ const enabledIndex = this._get(this._enabledAtom).findIndex((enabled) => enabled === id);
868
+ if (enabledIndex !== -1) {
869
+ this._update(this._enabledAtom, (enabled) => enabled.filter((item) => item !== id));
870
+ yield* this.deactivate(id);
871
+ plugin.modules.forEach((module) => {
872
+ this._removeModule(module.id);
873
+ });
874
+ }
875
+ return true;
876
+ });
877
+ }
878
+
879
+ /**
880
+ * Activates plugins based on the activation event.
881
+ * @param event The activation event.
882
+ * @returns Whether the activation was successful.
883
+ */
884
+ activate(
885
+ event: ActivationEvent.ActivationEvent | string,
886
+ params?: { before?: string; after?: string },
887
+ ): Effect.Effect<boolean, Error> {
888
+ const key = typeof event === 'string' ? event : ActivationEvent.eventKey(event);
889
+ return Effect.gen(this, function* () {
890
+ if (yield* this._isShuttingDown()) {
891
+ log('skipping activation during shutdown', { key, ...params });
892
+ return false;
893
+ }
894
+
895
+ // Wait for the constructor's core/enabled `enable()` chain — including
896
+ // any async dynamic imports for lazy plugins — to finish registering
897
+ // modules. Without this, dispatching to an empty module set is the
898
+ // observable symptom of the race.
899
+ yield* Deferred.await(this._initialization);
900
+
901
+ return yield* Effect.withFiberRuntime<boolean, Error>((fiber) =>
902
+ this._activateEvent(key, params, fiber).pipe(
903
+ together(
904
+ Effect.sleep(Duration.seconds(15)).pipe(
905
+ Effect.andThen(Effect.sync(() => log.warn('event activation is taking a long time', { event: key }))),
906
+ ),
907
+ ),
908
+ Performance.addTrackEntry({
909
+ name: typeof event === 'string' ? event : ActivationEvent.eventKey(event),
910
+ devtools: {
911
+ dataType: 'track-entry',
912
+ track: 'Event Activation',
913
+ trackGroup: 'Composer',
914
+ color: 'primary',
915
+ },
916
+ }),
917
+ ),
918
+ );
919
+ });
920
+ }
921
+
922
+ /**
923
+ * Deactivates all of the modules for a plugin.
924
+ * @param id The id of the plugin.
925
+ * @returns Whether the deactivation was successful.
926
+ */
927
+ deactivate(id: string): Effect.Effect<boolean, Error> {
928
+ return Effect.gen(this, function* () {
929
+ const plugin = this._getPlugin(id);
930
+ if (!plugin) {
931
+ return false;
932
+ }
933
+
934
+ const modules = plugin.modules;
935
+ const results = yield* Effect.all(
936
+ modules.map((module) => this._deactivateModule(module)),
937
+ { concurrency: 'unbounded' },
938
+ );
939
+ return results.every((result) => result);
940
+ });
941
+ }
942
+
943
+ /**
944
+ * Re-activates the modules that were activated by the event.
945
+ * @param event The activation event.
946
+ * @returns Whether the reset was successful.
947
+ */
948
+ reset(event: ActivationEvent.ActivationEvent | string): Effect.Effect<boolean, Error> {
949
+ return Effect.gen(this, function* () {
950
+ const key = typeof event === 'string' ? event : ActivationEvent.eventKey(event);
951
+ log('reset', { key });
952
+ const modules = this._getActiveModulesByEvent(key);
953
+ const results = yield* Effect.all(
954
+ modules.map((module) => this._deactivateModule(module)),
955
+ { concurrency: 'unbounded' },
956
+ );
957
+
958
+ if (results.every((result) => result)) {
959
+ return yield* this.activate(key);
960
+ } else {
961
+ return false;
962
+ }
963
+ });
964
+ }
965
+
966
+ shutdown(): Effect.Effect<boolean, Error> {
967
+ return this._shutdownSemaphore.withPermits(1)(
968
+ Effect.gen(this, function* () {
969
+ yield* Ref.set(this._shuttingDown, true);
970
+ log('shutdown');
971
+
972
+ yield* this._interruptInFlightActivations();
973
+
974
+ const activeIds = [...this._get(this._activeAtom)].reverse();
975
+ const allModules = this._get(this._modulesAtom);
976
+ const modulesToDeactivate = activeIds
977
+ .map((id) => allModules.find((module) => module.id === id))
978
+ .filter((module): module is Plugin.PluginModule => module != null);
979
+
980
+ for (const module of modulesToDeactivate) {
981
+ yield* this._deactivateModule(module);
982
+ }
983
+
984
+ this._set(this._eventsFiredAtom, []);
985
+ this._set(this._pendingResetAtom, []);
986
+ this._moduleMemoMap.clear();
987
+ yield* Ref.set(this._activatingEvents, []);
988
+ yield* Ref.set(this._activatingModules, []);
989
+
990
+ log('shutdown complete');
991
+ return true;
992
+ }).pipe(Effect.ensuring(Ref.set(this._shuttingDown, false))),
993
+ );
994
+ }
995
+
996
+ //
997
+ // State helpers
998
+ //
999
+
1000
+ private _get<T>(atom: Atom.Atom<T>): T {
1001
+ return this.registry.get(atom);
1002
+ }
1003
+
1004
+ private _set<T>(atom: Atom.Writable<T>, value: T): void {
1005
+ this.registry.set(atom, value);
1006
+ }
1007
+
1008
+ private _update<T>(atom: Atom.Writable<T>, updater: (current: T) => T): void {
1009
+ this._set(atom, updater(this._get(atom)));
1010
+ }
1011
+
1012
+ private _isShuttingDown(): Effect.Effect<boolean> {
1013
+ return Ref.get(this._shuttingDown);
1014
+ }
1015
+
1016
+ private _getPlugin(id: string): Plugin.Plugin | undefined {
1017
+ return this._get(this._pluginsAtom).find((plugin) => plugin.meta.id === id);
1018
+ }
1019
+
1020
+ private _getPluginIdForModule(moduleId: string): string | undefined {
1021
+ return this._get(this._pluginsAtom).find((plugin) => plugin.modules.some((module) => module.id === moduleId))?.meta
1022
+ .id;
1023
+ }
1024
+
1025
+ /** Looks up an id in the cached registry catalog, returning the entry or `undefined`. */
1026
+ private _getCatalogEntry(id: string): PluginRegistry.Plugin | undefined {
1027
+ return this._get(this.pluginRegistry.plugins).entries.find((entry) => entry.id === id);
1028
+ }
1029
+
1030
+ /**
1031
+ * Returns the direct `dependsOn` declarations for an id, drawing from the
1032
+ * registered plugin's meta when available and falling back to the registry
1033
+ * catalog entry. Unknown ids return an empty list (callers detect "missing"
1034
+ * separately).
1035
+ */
1036
+ private _directDependencies(id: string): string[] {
1037
+ const plugin = this._getPlugin(id);
1038
+ if (plugin) {
1039
+ return [...(plugin.meta.dependsOn ?? [])];
1040
+ }
1041
+ const catalog = this._getCatalogEntry(id);
1042
+ return catalog?.dependsOn ? [...catalog.dependsOn] : [];
1043
+ }
1044
+
1045
+ /**
1046
+ * Computes the transitive dependency closure for an id.
1047
+ *
1048
+ * Walks {@link _directDependencies} (registered plugins ∪ catalog entries).
1049
+ * Returns:
1050
+ * - `order`: closure including the root in dependency-first topological order.
1051
+ * - `missing`: ids in the closure that are neither registered nor in the catalog.
1052
+ * - `toInstall`: ids in the closure that are in the catalog but not yet registered.
1053
+ * - `cycle`: when a cycle is detected, the cycle path; otherwise `undefined`.
1054
+ */
1055
+ private _computeDependencyClosure(id: string): {
1056
+ order: string[];
1057
+ missing: string[];
1058
+ toInstall: string[];
1059
+ cycle?: string[];
1060
+ } {
1061
+ const order: string[] = [];
1062
+ const visited = new Set<string>();
1063
+ const onStack = new Set<string>();
1064
+ const stackPath: string[] = [];
1065
+ const missing: string[] = [];
1066
+ const toInstall: string[] = [];
1067
+ let cycle: string[] | undefined;
1068
+
1069
+ const knownIds = new Set<string>([
1070
+ ...this._get(this._pluginsAtom).map((plugin) => plugin.meta.id),
1071
+ ...this._get(this.pluginRegistry.plugins).entries.map((entry) => entry.id),
1072
+ ]);
1073
+
1074
+ const visit = (currentId: string): void => {
1075
+ if (cycle) {
1076
+ return;
1077
+ }
1078
+ if (visited.has(currentId)) {
1079
+ return;
1080
+ }
1081
+ if (onStack.has(currentId)) {
1082
+ const cycleStart = stackPath.indexOf(currentId);
1083
+ cycle = [...stackPath.slice(cycleStart), currentId];
1084
+ return;
1085
+ }
1086
+ onStack.add(currentId);
1087
+ stackPath.push(currentId);
1088
+
1089
+ if (!knownIds.has(currentId)) {
1090
+ missing.push(currentId);
1091
+ } else if (!this._getPlugin(currentId)) {
1092
+ toInstall.push(currentId);
1093
+ }
1094
+
1095
+ for (const depId of this._directDependencies(currentId)) {
1096
+ visit(depId);
1097
+ if (cycle) {
1098
+ break;
1099
+ }
1100
+ }
1101
+
1102
+ onStack.delete(currentId);
1103
+ stackPath.pop();
1104
+ if (!cycle) {
1105
+ visited.add(currentId);
1106
+ order.push(currentId);
1107
+ }
1108
+ };
1109
+
1110
+ visit(id);
1111
+ return { order, missing, toInstall, cycle };
1112
+ }
1113
+
1114
+ /**
1115
+ * Walks the reverse `dependsOn` edges across registered plugins. With
1116
+ * `enabledOnly`, filters the result to currently-enabled ids. Returns
1117
+ * dependents in dependents-before-deps order so callers (cascade-disable)
1118
+ * can iterate and tear down leaves first.
1119
+ */
1120
+ private _collectDependents(id: string, opts: { transitive: boolean; enabledOnly: boolean }): string[] {
1121
+ const direct = this._get(this._pluginsAtom)
1122
+ .filter((plugin) => plugin.meta.dependsOn?.includes(id))
1123
+ .map((plugin) => plugin.meta.id);
1124
+
1125
+ if (!opts.transitive) {
1126
+ return opts.enabledOnly
1127
+ ? direct.filter((dependentId) => this._get(this._enabledAtom).includes(dependentId))
1128
+ : direct;
1129
+ }
1130
+
1131
+ const result: string[] = [];
1132
+ const visited = new Set<string>();
1133
+ const visit = (currentId: string): void => {
1134
+ if (visited.has(currentId)) {
1135
+ return;
1136
+ }
1137
+ visited.add(currentId);
1138
+ const parents = this._get(this._pluginsAtom)
1139
+ .filter((plugin) => plugin.meta.dependsOn?.includes(currentId))
1140
+ .map((plugin) => plugin.meta.id);
1141
+ for (const parentId of parents) {
1142
+ visit(parentId);
1143
+ if (parentId !== id && !result.includes(parentId)) {
1144
+ result.push(parentId);
1145
+ }
1146
+ }
1147
+ };
1148
+ visit(id);
1149
+
1150
+ return opts.enabledOnly
1151
+ ? result.filter((dependentId) => this._get(this._enabledAtom).includes(dependentId))
1152
+ : result;
1153
+ }
1154
+
1155
+ /**
1156
+ * Records a failure for a plugin. Latest failure wins so the registry UI
1157
+ * always sees the most recent reason. Walks the `cause` chain when checking
1158
+ * for timeouts: lazy-load timeouts arrive wrapped in `LazyPluginError` (the
1159
+ * timeout is the cause), but the operator-visible reason should still be
1160
+ * `'timeout'`.
1161
+ */
1162
+ private _recordFailure(id: string, phase: PluginFailurePhase, error: Error): void {
1163
+ const reason: PluginFailureReason = isTimeoutCause(error) ? 'timeout' : 'error';
1164
+ const failure: PluginFailure = { id, phase, reason, error, timestamp: Date.now() };
1165
+ log.warn('plugin failed', { id, phase, reason, error: error.message });
1166
+ this._update(this._failedAtom, (current) => [...current.filter((entry) => entry.id !== id), failure]);
1167
+ }
1168
+
1169
+ /**
1170
+ * Fire-and-forget disable of a failed plugin. Forked because a failure can
1171
+ * happen mid-activation chain — yielding a `disable` inline would deadlock
1172
+ * on the shared semaphores. Core plugins are skipped (the host opted into
1173
+ * them being non-removable; the failure record is enough signal).
1174
+ */
1175
+ private _scheduleAutoDisable(id: string): void {
1176
+ if (this._get(this._coreAtom).includes(id)) {
1177
+ return;
1178
+ }
1179
+ if (!this._get(this._enabledAtom).includes(id)) {
1180
+ return;
1181
+ }
1182
+ this._runForkedFiber(
1183
+ this.disable(id).pipe(
1184
+ Effect.tapError((error) => Effect.sync(() => log.warn('auto-disable failed', { id, error }))),
1185
+ Effect.ignore,
1186
+ ),
1187
+ );
1188
+ }
1189
+
1190
+ private _getActiveModules(): Plugin.PluginModule[] {
1191
+ const active = this._get(this._activeAtom);
1192
+ return this._get(this._modulesAtom).filter((module) => active.includes(module.id));
1193
+ }
1194
+
1195
+ private _getInactiveModules(): Plugin.PluginModule[] {
1196
+ const active = this._get(this._activeAtom);
1197
+ return this._get(this._modulesAtom).filter((module) => !active.includes(module.id));
1198
+ }
1199
+
1200
+ private _getActiveModulesByEvent(key: string): Plugin.PluginModule[] {
1201
+ return this._getActiveModules().filter((module) =>
1202
+ ActivationEvent.getEvents(module.activatesOn).map(ActivationEvent.eventKey).includes(key),
1203
+ );
1204
+ }
1205
+
1206
+ private _getInactiveModulesByEvent(key: string): Plugin.PluginModule[] {
1207
+ return this._getInactiveModules().filter((module) =>
1208
+ ActivationEvent.getEvents(module.activatesOn).map(ActivationEvent.eventKey).includes(key),
1209
+ );
1210
+ }
1211
+
1212
+ private _setPendingResetByModule(module: Plugin.PluginModule): void {
1213
+ const activationEvents = ActivationEvent.getEvents(module.activatesOn)
1214
+ .map(ActivationEvent.eventKey)
1215
+ .filter((key) => this._get(this._eventsFiredAtom).includes(key));
1216
+
1217
+ const pendingReset = Array.fromIterable(new Set(activationEvents)).filter((event) => {
1218
+ const pending = this._get(this._pendingResetAtom);
1219
+ return !pending.includes(event);
1220
+ });
1221
+ if (pendingReset.length > 0) {
1222
+ log('pending reset', { events: pendingReset });
1223
+ this._update(this._pendingResetAtom, (current) => [...current, ...pendingReset]);
1224
+ }
1225
+ }
1226
+
1227
+ private _clearPendingReset(key: string): void {
1228
+ const pendingIndex = this._get(this._pendingResetAtom).findIndex((event) => event === key);
1229
+ if (pendingIndex !== -1) {
1230
+ this._update(this._pendingResetAtom, (pending) => pending.filter((event) => event !== key));
1231
+ }
1232
+ }
1233
+
1234
+ //
1235
+ // Fiber helpers
1236
+ //
1237
+
1238
+ private _interruptInFlightActivations(): Effect.Effect<void> {
1239
+ return Effect.gen(this, function* () {
1240
+ const inFlightFibers = yield* Ref.get(this._inFlightFibers);
1241
+ yield* Effect.forEach(inFlightFibers, (fiber) => Fiber.interrupt(fiber), {
1242
+ concurrency: 'unbounded',
1243
+ });
1244
+ });
1245
+ }
1246
+
1247
+ private _trackFiber(
1248
+ ref: Ref.Ref<Array<Fiber.Fiber<unknown, unknown>>>,
1249
+ fiber: Fiber.Fiber<unknown, unknown>,
1250
+ ): Effect.Effect<void> {
1251
+ return Ref.update(ref, (fibers) => [...fibers, fiber]);
1252
+ }
1253
+
1254
+ private _untrackFiber(
1255
+ ref: Ref.Ref<Array<Fiber.Fiber<unknown, unknown>>>,
1256
+ fiber: Fiber.Fiber<unknown, unknown>,
1257
+ ): Effect.Effect<void> {
1258
+ return Ref.update(ref, (fibers) => fibers.filter((trackedFiber) => trackedFiber !== fiber));
1259
+ }
1260
+
1261
+ /**
1262
+ * Spawns an effect on the default runtime and registers the resulting fiber in
1263
+ * `_inFlightFibers` so {@link shutdown} can interrupt it. Used from sync entry
1264
+ * points like {@link remove} where there is no enclosing Effect to fork from;
1265
+ * inside an Effect chain prefer the existing track/await/untrack pattern.
1266
+ */
1267
+ private _runForkedFiber<E>(effect: Effect.Effect<void, E>): void {
1268
+ const fiber = Effect.runFork(effect);
1269
+ Effect.runSync(this._trackFiber(this._inFlightFibers, fiber));
1270
+ Effect.runFork(Fiber.await(fiber).pipe(Effect.andThen(() => this._untrackFiber(this._inFlightFibers, fiber))));
1271
+ }
1272
+
1273
+ //
1274
+ // Registration helpers
1275
+ //
1276
+
1277
+ private _addPlugin(plugin: Plugin.Plugin): void {
1278
+ log('add plugin', { id: plugin.meta.id });
1279
+ // TODO(wittjosiah): Find a way to add a warning for duplicate plugins that doesn't cause log spam.
1280
+ this._update(this._pluginsAtom, (plugins) => (plugins.includes(plugin) ? plugins : [...plugins, plugin]));
1281
+ }
1282
+
1283
+ private _removePlugin(id: string): void {
1284
+ log('remove plugin', { id });
1285
+ this._update(this._pluginsAtom, (plugins) => plugins.filter((plugin) => plugin.meta.id !== id));
1286
+ }
1287
+
1288
+ private _addModule(module: Plugin.PluginModule): void {
1289
+ log('add module', { id: module.id });
1290
+ // TODO(wittjosiah): Find a way to add a warning for duplicate modules that doesn't cause log spam.
1291
+ this._update(this._modulesAtom, (modules) => (modules.includes(module) ? modules : [...modules, module]));
1292
+ }
1293
+
1294
+ private _removeModule(id: string): void {
1295
+ log('remove module', { id });
1296
+ this._update(this._modulesAtom, (modules) => modules.filter((module) => module.id !== id));
1297
+ }
1298
+
1299
+ //
1300
+ // Activation helpers
1301
+ //
1302
+
1303
+ private _activateEvent(
1304
+ key: string,
1305
+ params: { before?: string; after?: string } | undefined,
1306
+ fiber: Fiber.Fiber<unknown, unknown>,
1307
+ ): Effect.Effect<boolean, Error> {
1308
+ return Effect.gen(this, function* () {
1309
+ yield* this._trackFiber(this._inFlightFibers, fiber);
1310
+ log('activating', { key, ...params });
1311
+ yield* Ref.update(this._activatingEvents, (activating) => Array.append(activating, key));
1312
+ this._clearPendingReset(key);
1313
+
1314
+ const activatingEvents = yield* this._activatingEvents;
1315
+ const activatingModules = yield* this._activatingModules;
1316
+ const modules = this._getModulesForActivation(key, activatingEvents, activatingModules);
1317
+ if (modules.length === 0) {
1318
+ log('no modules to activate', { key });
1319
+ if (!this._get(this._eventsFiredAtom).includes(key)) {
1320
+ this._update(this._eventsFiredAtom, (events) => [...events, key]);
1321
+ }
1322
+ return false;
1323
+ }
1324
+
1325
+ return yield* this._activateModulesForEvent(key, modules, activatingEvents);
1326
+ }).pipe(
1327
+ Effect.ensuring(
1328
+ Effect.all([
1329
+ this._untrackFiber(this._inFlightFibers, fiber),
1330
+ Ref.update(this._activatingEvents, (activating) => Array.filter(activating, (event) => event !== key)),
1331
+ ]),
1332
+ ),
1333
+ );
1334
+ }
1335
+
1336
+ private _activateModulesForEvent(
1337
+ key: string,
1338
+ modules: Plugin.PluginModule[],
1339
+ activatingEvents: string[],
1340
+ ): Effect.Effect<boolean, Error> {
1341
+ const activatingModuleIds = modules.map((module) => module.id);
1342
+ return Effect.gen(this, function* () {
1343
+ yield* Ref.update(this._activatingModules, (activating) => Array.appendAll(activating, activatingModuleIds));
1344
+
1345
+ log('activating modules', { key, modules: activatingModuleIds });
1346
+ performance.mark(`event:${key}:start`);
1347
+ yield* PubSub.publish(this.activation, { event: key, state: 'activating' });
1348
+
1349
+ yield* this._activateRelatedEvents(key, this._getBeforeEvents(modules, activatingEvents), 'before');
1350
+
1351
+ const capabilities = yield* this._loadCapabilitiesForModules(key, modules);
1352
+ yield* this._contributeCapabilitiesForModules(modules, capabilities);
1353
+
1354
+ yield* this._activateRelatedEvents(key, this._getAfterEvents(modules, activatingEvents), 'after');
1355
+
1356
+ if (!this._get(this._eventsFiredAtom).includes(key)) {
1357
+ this._update(this._eventsFiredAtom, (events) => [...events, key]);
1358
+ }
1359
+
1360
+ performance.mark(`event:${key}:end`);
1361
+ performance.measure(`event:${key}`, `event:${key}:start`, `event:${key}:end`);
1362
+ yield* PubSub.publish(this.activation, { event: key, state: 'activated' });
1363
+ log('activated', { key });
1364
+
1365
+ return true;
1366
+ }).pipe(
1367
+ Effect.ensuring(
1368
+ Ref.update(this._activatingModules, (activating) =>
1369
+ Array.filter(activating, (module) => !activatingModuleIds.includes(module)),
1370
+ ),
1371
+ ),
1372
+ );
1373
+ }
1374
+
1375
+ private _getModulesForActivation(
1376
+ key: string,
1377
+ activatingEvents: string[],
1378
+ activatingModules: string[],
1379
+ ): Plugin.PluginModule[] {
1380
+ return this._getInactiveModulesByEvent(key).filter((module) => {
1381
+ const allOf = ActivationEvent.isAllOf(module.activatesOn);
1382
+ if (!allOf) {
1383
+ return true;
1384
+ }
1385
+
1386
+ // Check to see if all of the events in the `allOf` have been fired.
1387
+ // An event can be considered "fired" if it is in the `eventsFired` list or if it is currently being activated.
1388
+ const events = ActivationEvent.getEvents(module.activatesOn).filter(
1389
+ (event) => ActivationEvent.eventKey(event) !== key,
1390
+ );
1391
+ return (
1392
+ events.every(
1393
+ (event) =>
1394
+ this._get(this._eventsFiredAtom).includes(ActivationEvent.eventKey(event)) ||
1395
+ activatingEvents.includes(ActivationEvent.eventKey(event)),
1396
+ ) && !activatingModules.includes(module.id)
1397
+ );
1398
+ });
1399
+ }
1400
+
1401
+ private _getBeforeEvents(
1402
+ modules: Plugin.PluginModule[],
1403
+ activatingEvents: string[],
1404
+ ): ActivationEvent.ActivationEvent[] {
1405
+ return Function.pipe(
1406
+ modules,
1407
+ Array.flatMap((module) => module.firesBeforeActivation ?? []),
1408
+ HashSet.fromIterable,
1409
+ HashSet.toValues,
1410
+ Array.filter((event) => !activatingEvents.includes(ActivationEvent.eventKey(event))),
1411
+ );
1412
+ }
1413
+
1414
+ private _getAfterEvents(
1415
+ modules: Plugin.PluginModule[],
1416
+ activatingEvents: string[],
1417
+ ): ActivationEvent.ActivationEvent[] {
1418
+ return Function.pipe(
1419
+ modules,
1420
+ Array.flatMap((module) => module.firesAfterActivation ?? []),
1421
+ HashSet.fromIterable,
1422
+ HashSet.toValues,
1423
+ Array.filter((event) => !activatingEvents.includes(ActivationEvent.eventKey(event))),
1424
+ );
1425
+ }
1426
+
1427
+ private _activateRelatedEvents(
1428
+ key: string,
1429
+ events: ActivationEvent.ActivationEvent[],
1430
+ phase: 'before' | 'after',
1431
+ ): Effect.Effect<void, Error> {
1432
+ const logLabel = phase === 'before' ? 'firesBeforeActivation' : 'firesAfterActivation';
1433
+ const eventKey = phase === 'before' ? 'beforeEvents' : 'afterEvents';
1434
+ return Function.pipe(
1435
+ events,
1436
+ Array.map((event) => this.activate(event, phase === 'before' ? { before: key } : { after: key })),
1437
+ Effect.allWith({ concurrency: 'unbounded' }),
1438
+ together(
1439
+ Effect.sleep(Duration.seconds(10)).pipe(
1440
+ Effect.andThen(
1441
+ Effect.sync(() =>
1442
+ log.warn(`${logLabel} is taking a long time`, {
1443
+ event: key,
1444
+ [eventKey]: events.map(ActivationEvent.eventKey),
1445
+ }),
1446
+ ),
1447
+ ),
1448
+ ),
1449
+ ),
1450
+ Effect.asVoid,
1451
+ );
1452
+ }
1453
+
1454
+ //
1455
+ // Module lifecycle helpers
1456
+ //
1457
+
1458
+ private _loadCapabilitiesForModules(
1459
+ key: string,
1460
+ modules: Plugin.PluginModule[],
1461
+ ): Effect.Effect<Capability.Any[][], Error> {
1462
+ return Function.pipe(
1463
+ modules,
1464
+ Array.map((mod) => this._loadModule(mod, key)),
1465
+ Effect.allWith({ concurrency: 'unbounded' }),
1466
+ Effect.catchAll((error) => {
1467
+ return Effect.gen(this, function* () {
1468
+ yield* PubSub.publish(this.activation, { event: key, state: 'error', error });
1469
+ return yield* Effect.fail(error);
1470
+ });
1471
+ }),
1472
+ );
1473
+ }
1474
+
1475
+ private _contributeCapabilitiesForModules(
1476
+ modules: Plugin.PluginModule[],
1477
+ capabilities: Capability.Any[][],
1478
+ ): Effect.Effect<void, Error> {
1479
+ return Function.pipe(
1480
+ modules,
1481
+ Array.zip(capabilities),
1482
+ Array.map(([module, capabilitySet]) => this._contributeCapabilities(module, capabilitySet)),
1483
+ // TODO(wittjosiah): This currently can't be run in parallel, and inserting
1484
+ // any yield between contributions (`Effect.yieldNow()`, `Effect.sleep(0)`)
1485
+ // races the `allOf` activation-event resolver — observed as a System
1486
+ // Error dialog on warm reloads. Contributions must stay strictly
1487
+ // synchronous within an event; React paint slots have to be found at
1488
+ // event boundaries higher up the call chain.
1489
+ Effect.all,
1490
+ Effect.asVoid,
1491
+ );
1492
+ }
1493
+
1494
+ private _getModuleSemaphore(moduleId: Plugin.PluginModule['id']): Effect.Semaphore {
1495
+ let semaphore = this._moduleSemaphores.get(moduleId);
1496
+ if (!semaphore) {
1497
+ semaphore = Effect.runSync(Effect.makeSemaphore(1));
1498
+ this._moduleSemaphores.set(moduleId, semaphore);
1499
+ }
1500
+ return semaphore;
1501
+ }
1502
+
1503
+ // `parentEvent` is the activation event that first triggered this module
1504
+ // load — included in `activating`/`activated` PubSub messages so subscribers
1505
+ // (e.g. the boot loader's status listener) can associate a module with its
1506
+ // triggering event in the trace. The same module may be referenced by
1507
+ // multiple events, but module loads are memoized via `_moduleMemoMap`, so
1508
+ // only the first event to need it will appear here; later events await the
1509
+ // cached deferred without re-publishing.
1510
+ private _loadModule = (module: Plugin.PluginModule, parentEvent: string): Effect.Effect<Capability.Any[], Error> =>
1511
+ Effect.gen(this, function* () {
1512
+ const semaphore = this._getModuleSemaphore(module.id);
1513
+
1514
+ // Atomically check-and-set under per-module semaphore to prevent race conditions.
1515
+ const deferredToAwait = yield* Effect.gen(this, function* () {
1516
+ const existing = this._moduleMemoMap.get(module.id);
1517
+ if (existing) {
1518
+ return existing;
1519
+ }
1520
+
1521
+ // First caller - create deferred, store it, and start loading in background.
1522
+ const deferred = yield* Deferred.make<Capability.Any[], Error>();
1523
+ this._moduleMemoMap.set(module.id, deferred);
1524
+
1525
+ const loadEffect = Effect.gen(this, function* () {
1526
+ log('loading module', { module: module.id, parentEvent });
1527
+ performance.mark(`module:${module.id}:start`);
1528
+ yield* PubSub.publish(this.activation, { event: parentEvent, state: 'activating', module: module.id });
1529
+ const pluginId = this._getPluginIdForModule(module.id);
1530
+ const [duration, capabilities] = yield* module.activate().pipe(
1531
+ Effect.provideService(Capability.Service, this.capabilities),
1532
+ Effect.provideService(Plugin.Service, this),
1533
+ // Cap activation so a single misbehaving module can't hold the
1534
+ // event chain open. On timeout the failure is recorded against
1535
+ // the plugin and surfaced as `PluginTimeoutError`.
1536
+ Effect.timeoutFail({
1537
+ duration: this._activationTimeout,
1538
+ onTimeout: () =>
1539
+ new PluginTimeoutError({
1540
+ context: { id: pluginId ?? module.id, module: module.id, phase: 'activation' as PluginFailurePhase },
1541
+ }),
1542
+ }),
1543
+ Effect.timed,
1544
+ );
1545
+ const normalized = capabilities == null ? [] : Array.isArray(capabilities) ? capabilities : [capabilities];
1546
+ const elapsed = Duration.toMillis(duration);
1547
+ performance.mark(`module:${module.id}:end`);
1548
+ performance.measure(`module:${module.id}`, `module:${module.id}:start`, `module:${module.id}:end`);
1549
+ yield* PubSub.publish(this.activation, { event: parentEvent, state: 'activated', module: module.id });
1550
+ log('loaded module', {
1551
+ module: module.id,
1552
+ parentEvent,
1553
+ elapsed,
1554
+ failed: false,
1555
+ });
1556
+ return normalized as Capability.Any[];
1557
+ }).pipe(
1558
+ Effect.withSpan('PluginManager._loadModule'),
1559
+ together(
1560
+ Effect.sleep(Duration.seconds(10)).pipe(
1561
+ Effect.andThen(
1562
+ Effect.sync(() => log.warn(`module is taking a long time to activate`, { module: module.id })),
1563
+ ),
1564
+ ),
1565
+ ),
1566
+ Performance.addTrackEntry({
1567
+ name: module.id,
1568
+ devtools: {
1569
+ dataType: 'track-entry',
1570
+ track: 'Module Activation',
1571
+ trackGroup: 'Composer',
1572
+ color: 'primary',
1573
+ },
1574
+ }),
1575
+ );
1576
+
1577
+ // Fork the load to run in background, completing the deferred when done.
1578
+ const fiber = yield* Effect.forkDaemon(
1579
+ loadEffect.pipe(
1580
+ Effect.tap((result) => Deferred.succeed(deferred, result)),
1581
+ Effect.catchAllCause((cause) => {
1582
+ const error = Cause.squash(cause);
1583
+ log.error('module failed to activate', {
1584
+ module: module.id,
1585
+ error: error instanceof Error ? error.message : String(error),
1586
+ stack: error instanceof Error ? error.stack : undefined,
1587
+ isDefect: !Cause.isFailure(cause),
1588
+ });
1589
+ const normalizedError = error instanceof Error ? error : new Error(String(error));
1590
+ const pluginId = this._getPluginIdForModule(module.id);
1591
+ if (pluginId !== undefined) {
1592
+ this._recordFailure(pluginId, 'activation', normalizedError);
1593
+ this._scheduleAutoDisable(pluginId);
1594
+ }
1595
+ return Deferred.fail(deferred, normalizedError);
1596
+ }),
1597
+ ),
1598
+ );
1599
+ yield* this._trackFiber(this._inFlightFibers, fiber);
1600
+ yield* Effect.forkDaemon(
1601
+ Fiber.await(fiber).pipe(Effect.andThen(() => this._untrackFiber(this._inFlightFibers, fiber))),
1602
+ );
1603
+
1604
+ return deferred;
1605
+ }).pipe(semaphore.withPermits(1));
1606
+
1607
+ // Wait for result outside the semaphore so multiple waiters can proceed concurrently.
1608
+ return yield* Deferred.await(deferredToAwait);
1609
+ });
1610
+
1611
+ private _contributeCapabilities(
1612
+ module: Plugin.PluginModule,
1613
+ capabilities: Capability.Any[],
1614
+ ): Effect.Effect<void, Error> {
1615
+ return Effect.gen(this, function* () {
1616
+ capabilities.forEach((capability) => {
1617
+ this.capabilities.contribute({ module: module.id, ...capability });
1618
+ });
1619
+ this._update(this._activeAtom, (active) => [...active, module.id]);
1620
+ this._capabilities.set(module.id, capabilities);
1621
+ });
1622
+ }
1623
+
1624
+ private _deactivateModule(module: Plugin.PluginModule): Effect.Effect<boolean, Error> {
1625
+ return Effect.gen(this, function* () {
1626
+ const id = module.id;
1627
+ log('deactivating', { id });
1628
+ this._moduleMemoMap.delete(id);
1629
+
1630
+ const capabilities = this._capabilities.get(id);
1631
+ if (capabilities) {
1632
+ for (const capability of capabilities) {
1633
+ this.capabilities.remove(capability.interface, capability.implementation);
1634
+ const program = capability.deactivate?.() ?? Effect.succeed(undefined);
1635
+ yield* program;
1636
+ }
1637
+ this._capabilities.delete(id);
1638
+ }
1639
+
1640
+ const activeIndex = this._get(this._activeAtom).findIndex((event) => event === id);
1641
+ if (activeIndex !== -1) {
1642
+ this._update(this._activeAtom, (active) => active.filter((event) => event !== id));
1643
+ }
1644
+
1645
+ log('deactivated', { id });
1646
+ return true;
1647
+ });
1648
+ }
1649
+ }
1650
+
1651
+ /**
1652
+ * Creates a new Plugin Manager instance.
1653
+ */
1654
+ export const make = (options: ManagerOptions): PluginManager => new ManagerImpl(options);
1655
+
1656
+ /**
1657
+ * True when `error` (or anything along its `cause` chain) is a
1658
+ * {@link PluginTimeoutError}. Lazy-load timeouts wrap the timeout inside
1659
+ * `LazyPluginError`, so a shallow check on the outer error misses them.
1660
+ * Bounded depth so a circular chain can't loop forever.
1661
+ */
1662
+ const isTimeoutCause = (error: unknown, depth = 0): boolean => {
1663
+ if (depth > 5 || !(error instanceof Error)) {
1664
+ return false;
1665
+ }
1666
+ if (PluginTimeoutError.is(error)) {
1667
+ return true;
1668
+ }
1669
+ return isTimeoutCause((error as Error & { cause?: unknown }).cause, depth + 1);
1670
+ };
1671
+
1672
+ /**
1673
+ * Runs an effect concurrently with another effect.
1674
+ * If the first effect completes, the second effect is interrupted.
1675
+ */
1676
+ // TODO(dmaretskyi): Effect.race > Effect.asVoid
1677
+ const together =
1678
+ <R1>(togetherEffect: Effect.Effect<void, never, R1>) =>
1679
+ <A, E, R2>(effect: Effect.Effect<A, E, R2>): Effect.Effect<A, E, R1 | R2> =>
1680
+ Effect.gen(function* () {
1681
+ const togetherFiber = yield* Effect.fork(togetherEffect);
1682
+ const result = yield* effect;
1683
+ yield* Fiber.interrupt(togetherFiber);
1684
+ return result;
1685
+ });