@dxos/app-framework 0.8.4-main.84f28bd → 0.8.4-main.8baae0fced

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