@dxos/app-framework 0.8.4-main.422d1c7879 → 0.8.4-main.4f23b4e393

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 (272) hide show
  1. package/dist/lib/browser/{capability-DOMNPRJP.mjs → capability-5RRH3WIB.mjs} +11 -11
  2. package/dist/lib/browser/capability-5RRH3WIB.mjs.map +7 -0
  3. package/dist/lib/browser/{capability-KSNT34SN.mjs → capability-LUKGKUQH.mjs} +10 -10
  4. package/dist/lib/browser/{chunk-T3Y4AEKX.mjs → chunk-23D4SJUE.mjs} +3 -3
  5. package/dist/lib/browser/{chunk-T3Y4AEKX.mjs.map → chunk-23D4SJUE.mjs.map} +1 -1
  6. package/dist/lib/browser/{chunk-2CKCJ6PN.mjs → chunk-3JWJXGLK.mjs} +1 -1
  7. package/dist/lib/browser/{chunk-2CKCJ6PN.mjs.map → chunk-3JWJXGLK.mjs.map} +1 -1
  8. package/dist/lib/browser/{chunk-I34GF4NG.mjs → chunk-45CHLTBV.mjs} +2 -2
  9. package/dist/lib/browser/{chunk-QSXYHXCE.mjs → chunk-66IXTIVK.mjs} +1 -1
  10. package/dist/lib/browser/{chunk-QSXYHXCE.mjs.map → chunk-66IXTIVK.mjs.map} +2 -2
  11. package/dist/lib/browser/{chunk-QRTB4Q3U.mjs → chunk-7VZJR2OA.mjs} +4 -17
  12. package/dist/lib/browser/chunk-7VZJR2OA.mjs.map +7 -0
  13. package/dist/lib/browser/chunk-CZ4BIAHH.mjs +422 -0
  14. package/dist/lib/browser/chunk-CZ4BIAHH.mjs.map +7 -0
  15. package/dist/lib/browser/{chunk-TGX63LTL.mjs → chunk-FJ4765WW.mjs} +1 -1
  16. package/dist/lib/browser/{chunk-TGX63LTL.mjs.map → chunk-FJ4765WW.mjs.map} +2 -2
  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-BMIAYUWT.mjs → chunk-JD3Z5NEF.mjs} +147 -75
  20. package/dist/lib/browser/chunk-JD3Z5NEF.mjs.map +7 -0
  21. package/dist/lib/browser/chunk-NBXPP7JR.mjs +1174 -0
  22. package/dist/lib/browser/chunk-NBXPP7JR.mjs.map +7 -0
  23. package/dist/lib/browser/{chunk-JKWMHZP6.mjs → chunk-WBHCSOBW.mjs} +2 -2
  24. package/dist/lib/browser/chunk-WBHCSOBW.mjs.map +7 -0
  25. package/dist/lib/browser/{chunk-GDWTW4ZW.mjs → chunk-Z55LVAGN.mjs} +76 -11
  26. package/dist/lib/browser/chunk-Z55LVAGN.mjs.map +7 -0
  27. package/dist/lib/browser/{chunk-F7FW2RK2.mjs → chunk-ZGJAZSNE.mjs} +7 -32
  28. package/dist/lib/browser/chunk-ZGJAZSNE.mjs.map +7 -0
  29. package/dist/lib/browser/cli/index.mjs +14 -28
  30. package/dist/lib/browser/cli/index.mjs.map +3 -3
  31. package/dist/lib/browser/common/activation-events.mjs +7 -7
  32. package/dist/lib/browser/common/capabilities.mjs +7 -7
  33. package/dist/lib/browser/core/activation-event.mjs +1 -1
  34. package/dist/lib/browser/core/capability.mjs +1 -1
  35. package/dist/lib/browser/core/plugin-manager.mjs +8 -4
  36. package/dist/lib/browser/core/plugin.mjs +10 -2
  37. package/dist/lib/browser/core/url-loader.mjs +13 -5
  38. package/dist/lib/browser/index.mjs +34 -17
  39. package/dist/lib/browser/index.mjs.map +3 -3
  40. package/dist/lib/browser/{invoker-capability-VCMPQOIA.mjs → invoker-capability-K4GHUFXF.mjs} +12 -11
  41. package/dist/lib/browser/invoker-capability-K4GHUFXF.mjs.map +7 -0
  42. package/dist/lib/browser/meta.json +1 -1
  43. package/dist/lib/browser/testing/index.mjs +20 -32
  44. package/dist/lib/browser/testing/index.mjs.map +3 -3
  45. package/dist/lib/browser/testing/react.mjs +11 -11
  46. package/dist/lib/browser/ui/index.mjs +14 -12
  47. package/dist/lib/node-esm/{capability-EOQTORML.mjs → capability-FCGZVIEG.mjs} +10 -10
  48. package/dist/lib/node-esm/{capability-KJTQIWDK.mjs → capability-JOIQ2MQE.mjs} +11 -11
  49. package/dist/lib/node-esm/capability-JOIQ2MQE.mjs.map +7 -0
  50. package/dist/lib/node-esm/{chunk-FKE4Z3D6.mjs → chunk-37Z53PXZ.mjs} +1 -1
  51. package/dist/lib/node-esm/{chunk-FKE4Z3D6.mjs.map → chunk-37Z53PXZ.mjs.map} +2 -2
  52. package/dist/lib/node-esm/{chunk-WZCSOX5Q.mjs → chunk-6XW6LET6.mjs} +2 -2
  53. package/dist/lib/node-esm/{chunk-URWHJQT2.mjs → chunk-D347W3KO.mjs} +7 -32
  54. package/dist/lib/node-esm/chunk-D347W3KO.mjs.map +7 -0
  55. package/dist/lib/node-esm/{chunk-WZ6DHQER.mjs → chunk-DRZKO5UZ.mjs} +147 -75
  56. package/dist/lib/node-esm/chunk-DRZKO5UZ.mjs.map +7 -0
  57. package/dist/lib/node-esm/{chunk-HI3YBICQ.mjs → chunk-HTBJU5FX.mjs} +76 -11
  58. package/dist/lib/node-esm/chunk-HTBJU5FX.mjs.map +7 -0
  59. package/dist/lib/node-esm/chunk-M3HKPRPO.mjs +423 -0
  60. package/dist/lib/node-esm/chunk-M3HKPRPO.mjs.map +7 -0
  61. package/dist/lib/node-esm/chunk-MUVUQC3G.mjs +1175 -0
  62. package/dist/lib/node-esm/chunk-MUVUQC3G.mjs.map +7 -0
  63. package/dist/lib/node-esm/{chunk-VKHGNEDB.mjs → chunk-SBS2YMPT.mjs} +3 -3
  64. package/dist/lib/node-esm/{chunk-VKHGNEDB.mjs.map → chunk-SBS2YMPT.mjs.map} +1 -1
  65. package/dist/lib/node-esm/{chunk-42KBWDE4.mjs → chunk-SDJ4B2LU.mjs} +1 -1
  66. package/dist/lib/node-esm/{chunk-42KBWDE4.mjs.map → chunk-SDJ4B2LU.mjs.map} +1 -1
  67. package/dist/lib/node-esm/{chunk-JPWVIQ5I.mjs → chunk-V24UWT36.mjs} +4 -17
  68. package/dist/lib/node-esm/chunk-V24UWT36.mjs.map +7 -0
  69. package/dist/lib/node-esm/{chunk-G3RTFSNG.mjs → chunk-WFSRZKBP.mjs} +2 -2
  70. package/dist/lib/node-esm/chunk-WFSRZKBP.mjs.map +7 -0
  71. package/dist/lib/node-esm/chunk-WK7OIQKI.mjs +70 -0
  72. package/dist/lib/node-esm/chunk-WK7OIQKI.mjs.map +7 -0
  73. package/dist/lib/node-esm/{chunk-ZZ7CKK6W.mjs → chunk-XOCUANHO.mjs} +1 -1
  74. package/dist/lib/node-esm/{chunk-ZZ7CKK6W.mjs.map → chunk-XOCUANHO.mjs.map} +2 -2
  75. package/dist/lib/node-esm/cli/index.mjs +14 -28
  76. package/dist/lib/node-esm/cli/index.mjs.map +3 -3
  77. package/dist/lib/node-esm/common/activation-events.mjs +7 -7
  78. package/dist/lib/node-esm/common/capabilities.mjs +7 -7
  79. package/dist/lib/node-esm/core/activation-event.mjs +1 -1
  80. package/dist/lib/node-esm/core/capability.mjs +1 -1
  81. package/dist/lib/node-esm/core/plugin-manager.mjs +8 -4
  82. package/dist/lib/node-esm/core/plugin.mjs +10 -2
  83. package/dist/lib/node-esm/core/url-loader.mjs +13 -5
  84. package/dist/lib/node-esm/index.mjs +34 -17
  85. package/dist/lib/node-esm/index.mjs.map +3 -3
  86. package/dist/lib/node-esm/{invoker-capability-EGA3XW6J.mjs → invoker-capability-XEPW5LMJ.mjs} +12 -11
  87. package/dist/lib/node-esm/invoker-capability-XEPW5LMJ.mjs.map +7 -0
  88. package/dist/lib/node-esm/meta.json +1 -1
  89. package/dist/lib/node-esm/testing/index.mjs +20 -32
  90. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  91. package/dist/lib/node-esm/testing/react.mjs +11 -11
  92. package/dist/lib/node-esm/ui/index.mjs +14 -12
  93. package/dist/plugin/node-esm/index.mjs +136 -37
  94. package/dist/plugin/node-esm/index.mjs.map +4 -4
  95. package/dist/plugin/node-esm/meta.json +1 -1
  96. package/dist/types/src/common/annotations.d.ts +1 -0
  97. package/dist/types/src/common/annotations.d.ts.map +1 -0
  98. package/dist/types/src/common/capabilities.d.ts +2 -1
  99. package/dist/types/src/common/capabilities.d.ts.map +1 -1
  100. package/dist/types/src/common/operations.d.ts +1 -1
  101. package/dist/types/src/common/operations.d.ts.map +1 -1
  102. package/dist/types/src/core/activation-event.d.ts +4 -4
  103. package/dist/types/src/core/activation-event.d.ts.map +1 -1
  104. package/dist/types/src/core/capability-manager.d.ts.map +1 -1
  105. package/dist/types/src/core/capability.d.ts +2 -2
  106. package/dist/types/src/core/capability.d.ts.map +1 -1
  107. package/dist/types/src/core/edge-registry-plugin-provider.d.ts +30 -0
  108. package/dist/types/src/core/edge-registry-plugin-provider.d.ts.map +1 -0
  109. package/dist/types/src/core/index.d.ts +5 -0
  110. package/dist/types/src/core/index.d.ts.map +1 -1
  111. package/dist/types/src/core/plugin-asset-cache.d.ts +71 -0
  112. package/dist/types/src/core/plugin-asset-cache.d.ts.map +1 -0
  113. package/dist/types/src/core/plugin-manager.d.ts +163 -2
  114. package/dist/types/src/core/plugin-manager.d.ts.map +1 -1
  115. package/dist/types/src/core/plugin-manifest.d.ts +101 -0
  116. package/dist/types/src/core/plugin-manifest.d.ts.map +1 -0
  117. package/dist/types/src/core/plugin-manifest.test.d.ts +2 -0
  118. package/dist/types/src/core/plugin-manifest.test.d.ts.map +1 -0
  119. package/dist/types/src/core/plugin.d.ts +80 -0
  120. package/dist/types/src/core/plugin.d.ts.map +1 -1
  121. package/dist/types/src/core/registry.d.ts +101 -0
  122. package/dist/types/src/core/registry.d.ts.map +1 -0
  123. package/dist/types/src/core/url-loader.d.ts +88 -3
  124. package/dist/types/src/core/url-loader.d.ts.map +1 -1
  125. package/dist/types/src/helpers.d.ts.map +1 -1
  126. package/dist/types/src/plugin-operation/history/capability.d.ts.map +1 -1
  127. package/dist/types/src/plugin-operation/history/errors.d.ts +6 -6
  128. package/dist/types/src/plugin-operation/history/errors.d.ts.map +1 -1
  129. package/dist/types/src/plugin-operation/history/history-tracker.d.ts +1 -1
  130. package/dist/types/src/plugin-operation/history/history-tracker.d.ts.map +1 -1
  131. package/dist/types/src/plugin-operation/history/types.d.ts +1 -1
  132. package/dist/types/src/plugin-operation/history/types.d.ts.map +1 -1
  133. package/dist/types/src/plugin-operation/history/undo-mapping.d.ts +1 -1
  134. package/dist/types/src/plugin-operation/history/undo-mapping.d.ts.map +1 -1
  135. package/dist/types/src/plugin-operation/history/undo-registry.d.ts +1 -1
  136. package/dist/types/src/plugin-operation/history/undo-registry.d.ts.map +1 -1
  137. package/dist/types/src/plugin-operation/invoker-capability.d.ts +1 -1
  138. package/dist/types/src/plugin-operation/invoker-capability.d.ts.map +1 -1
  139. package/dist/types/src/plugin-operation/meta.d.ts.map +1 -1
  140. package/dist/types/src/plugin-operation/testing.d.ts +2 -1
  141. package/dist/types/src/plugin-operation/testing.d.ts.map +1 -1
  142. package/dist/types/src/plugin-runtime/capability.d.ts +1 -1
  143. package/dist/types/src/plugin-runtime/capability.d.ts.map +1 -1
  144. package/dist/types/src/plugin-runtime/meta.d.ts.map +1 -1
  145. package/dist/types/src/testing/harness.d.ts +1 -1
  146. package/dist/types/src/testing/harness.d.ts.map +1 -1
  147. package/dist/types/src/testing/react.d.ts.map +1 -1
  148. package/dist/types/src/testing/service.d.ts.map +1 -1
  149. package/dist/types/src/testing/withPluginManager.d.ts.map +1 -1
  150. package/dist/types/src/testing/withPluginManager.stories.d.ts.map +1 -1
  151. package/dist/types/src/ui/components/App/App.d.ts.map +1 -1
  152. package/dist/types/src/ui/components/App/App.stories.d.ts.map +1 -1
  153. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts +64 -0
  154. package/dist/types/src/ui/components/Placeholder/Placeholder.d.ts.map +1 -0
  155. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts +19 -0
  156. package/dist/types/src/ui/components/Placeholder/Placeholder.stories.d.ts.map +1 -0
  157. package/dist/types/src/ui/components/Placeholder/index.d.ts +2 -0
  158. package/dist/types/src/ui/components/Placeholder/index.d.ts.map +1 -0
  159. package/dist/types/src/ui/components/PluginManager/PluginManagerContext.stories.d.ts.map +1 -1
  160. package/dist/types/src/ui/components/Surface/SurfaceComponent.stories.d.ts.map +1 -1
  161. package/dist/types/src/ui/components/Surface/SurfaceInfo.d.ts.map +1 -1
  162. package/dist/types/src/ui/components/Surface/SurfaceProfilerContext.d.ts.map +1 -1
  163. package/dist/types/src/ui/components/Surface/index.d.ts +1 -1
  164. package/dist/types/src/ui/components/Surface/index.d.ts.map +1 -1
  165. package/dist/types/src/ui/components/Surface/types.d.ts.map +1 -1
  166. package/dist/types/src/ui/components/index.d.ts +1 -0
  167. package/dist/types/src/ui/components/index.d.ts.map +1 -1
  168. package/dist/types/src/ui/hooks/useApp.d.ts +30 -3
  169. package/dist/types/src/ui/hooks/useApp.d.ts.map +1 -1
  170. package/dist/types/src/ui/hooks/useCapabilities.d.ts.map +1 -1
  171. package/dist/types/src/ui/hooks/useLoading.d.ts.map +1 -1
  172. package/dist/types/src/ui/hooks/useSettingsState.d.ts.map +1 -1
  173. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts +20 -36
  174. package/dist/types/src/vite-plugin/boot-loader/BootLoader.stories.d.ts.map +1 -1
  175. package/dist/types/src/vite-plugin/boot-loader/index.d.ts +1 -50
  176. package/dist/types/src/vite-plugin/boot-loader/index.d.ts.map +1 -1
  177. package/dist/types/src/vite-plugin/boot-loader/loader.d.ts +51 -0
  178. package/dist/types/src/vite-plugin/boot-loader/loader.d.ts.map +1 -0
  179. package/dist/types/src/vite-plugin/composer/index.d.ts +12 -12
  180. package/dist/types/src/vite-plugin/composer/index.d.ts.map +1 -1
  181. package/dist/types/src/vite-plugin/import-map/index.d.ts +13 -1
  182. package/dist/types/src/vite-plugin/import-map/index.d.ts.map +1 -1
  183. package/dist/types/src/vite-plugin/manifest.d.ts +30 -5
  184. package/dist/types/src/vite-plugin/manifest.d.ts.map +1 -1
  185. package/dist/types/src/vite-plugin/packages.d.ts.map +1 -1
  186. package/dist/types/tsconfig.tsbuildinfo +1 -1
  187. package/package.json +27 -23
  188. package/src/cli/cli.ts +1 -1
  189. package/src/common/annotations.ts +3 -0
  190. package/src/common/capabilities.ts +2 -1
  191. package/src/common/operations.ts +1 -1
  192. package/src/core/capability.ts +1 -1
  193. package/src/core/edge-registry-plugin-provider.ts +92 -0
  194. package/src/core/index.ts +5 -0
  195. package/src/core/plugin-asset-cache.ts +60 -0
  196. package/src/core/plugin-manager.test.ts +533 -4
  197. package/src/core/plugin-manager.ts +470 -28
  198. package/src/core/plugin-manifest.test.ts +75 -0
  199. package/src/core/plugin-manifest.ts +134 -0
  200. package/src/core/plugin.ts +103 -0
  201. package/src/core/registry.ts +157 -0
  202. package/src/core/url-loader.test.ts +115 -6
  203. package/src/core/url-loader.ts +253 -43
  204. package/src/plugin-operation/history/capability.ts +1 -1
  205. package/src/plugin-operation/history/history-tracker.test.ts +2 -1
  206. package/src/plugin-operation/history/history-tracker.ts +1 -1
  207. package/src/plugin-operation/history/types.ts +1 -1
  208. package/src/plugin-operation/history/undo-mapping.ts +1 -1
  209. package/src/plugin-operation/history/undo-registry.ts +1 -1
  210. package/src/plugin-operation/invoker-capability.ts +2 -1
  211. package/src/plugin-operation/meta.ts +1 -0
  212. package/src/plugin-operation/testing.ts +2 -1
  213. package/src/plugin-runtime/meta.ts +1 -0
  214. package/src/testing/harness.ts +2 -2
  215. package/src/testing/service.ts +1 -1
  216. package/src/testing/withPluginManager.stories.tsx +1 -1
  217. package/src/ui/components/App/App.stories.tsx +2 -6
  218. package/src/ui/components/App/App.tsx +12 -1
  219. package/src/ui/components/Placeholder/Placeholder.stories.tsx +77 -0
  220. package/src/ui/components/Placeholder/Placeholder.tsx +155 -0
  221. package/src/ui/components/Placeholder/index.ts +5 -0
  222. package/src/ui/components/PluginManager/PluginManagerContext.stories.tsx +4 -2
  223. package/src/ui/components/Surface/SurfaceComponent.stories.tsx +1 -1
  224. package/src/ui/components/Surface/SurfaceComponent.tsx +2 -2
  225. package/src/ui/components/Surface/SurfaceInfo.tsx +0 -1
  226. package/src/ui/components/index.ts +1 -0
  227. package/src/ui/hooks/useApp.test.tsx +1 -1
  228. package/src/ui/hooks/useApp.tsx +161 -26
  229. package/src/ui/hooks/useLoading.tsx +14 -6
  230. package/src/vite-plugin/boot-loader/BootLoader.stories.tsx +208 -100
  231. package/src/vite-plugin/boot-loader/boot-loader.css +248 -45
  232. package/src/vite-plugin/boot-loader/boot-loader.js +309 -39
  233. package/src/vite-plugin/boot-loader/index.ts +1 -95
  234. package/src/vite-plugin/boot-loader/loader.ts +123 -0
  235. package/src/vite-plugin/composer/index.ts +61 -39
  236. package/src/vite-plugin/import-map/index.ts +42 -5
  237. package/src/vite-plugin/index.ts +2 -2
  238. package/src/vite-plugin/manifest.test.ts +27 -4
  239. package/src/vite-plugin/manifest.ts +42 -5
  240. package/src/vite-plugin/packages.ts +8 -2
  241. package/tsconfig.json +16 -1
  242. package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  243. package/dist/lib/browser/capability-DOMNPRJP.mjs.map +0 -7
  244. package/dist/lib/browser/chunk-7B6AJK4D.mjs +0 -964
  245. package/dist/lib/browser/chunk-7B6AJK4D.mjs.map +0 -7
  246. package/dist/lib/browser/chunk-BMIAYUWT.mjs.map +0 -7
  247. package/dist/lib/browser/chunk-F7FW2RK2.mjs.map +0 -7
  248. package/dist/lib/browser/chunk-GDWTW4ZW.mjs.map +0 -7
  249. package/dist/lib/browser/chunk-JKWMHZP6.mjs.map +0 -7
  250. package/dist/lib/browser/chunk-QRTB4Q3U.mjs.map +0 -7
  251. package/dist/lib/browser/chunk-RFSO3JRG.mjs +0 -1
  252. package/dist/lib/browser/chunk-RFSO3JRG.mjs.map +0 -7
  253. package/dist/lib/browser/chunk-Y543KCO7.mjs +0 -174
  254. package/dist/lib/browser/chunk-Y543KCO7.mjs.map +0 -7
  255. package/dist/lib/browser/invoker-capability-VCMPQOIA.mjs.map +0 -7
  256. package/dist/lib/node-esm/capability-KJTQIWDK.mjs.map +0 -7
  257. package/dist/lib/node-esm/chunk-7PJ5OKRB.mjs +0 -965
  258. package/dist/lib/node-esm/chunk-7PJ5OKRB.mjs.map +0 -7
  259. package/dist/lib/node-esm/chunk-DXVXOGJ7.mjs +0 -175
  260. package/dist/lib/node-esm/chunk-DXVXOGJ7.mjs.map +0 -7
  261. package/dist/lib/node-esm/chunk-EL3R25OQ.mjs +0 -2
  262. package/dist/lib/node-esm/chunk-EL3R25OQ.mjs.map +0 -7
  263. package/dist/lib/node-esm/chunk-G3RTFSNG.mjs.map +0 -7
  264. package/dist/lib/node-esm/chunk-HI3YBICQ.mjs.map +0 -7
  265. package/dist/lib/node-esm/chunk-JPWVIQ5I.mjs.map +0 -7
  266. package/dist/lib/node-esm/chunk-URWHJQT2.mjs.map +0 -7
  267. package/dist/lib/node-esm/chunk-WZ6DHQER.mjs.map +0 -7
  268. package/dist/lib/node-esm/invoker-capability-EGA3XW6J.mjs.map +0 -7
  269. /package/dist/lib/browser/{capability-KSNT34SN.mjs.map → capability-LUKGKUQH.mjs.map} +0 -0
  270. /package/dist/lib/browser/{chunk-I34GF4NG.mjs.map → chunk-45CHLTBV.mjs.map} +0 -0
  271. /package/dist/lib/node-esm/{capability-EOQTORML.mjs.map → capability-FCGZVIEG.mjs.map} +0 -0
  272. /package/dist/lib/node-esm/{chunk-WZCSOX5Q.mjs.map → chunk-6XW6LET6.mjs.map} +0 -0
@@ -16,12 +16,64 @@ import * as Ref from 'effect/Ref';
16
16
 
17
17
  import { runAndForwardErrors } from '@dxos/effect';
18
18
  import { Performance } from '@dxos/effect';
19
+ import { BaseError } from '@dxos/errors';
19
20
  import { log } from '@dxos/log';
20
21
 
21
22
  import * as ActivationEvent from './activation-event';
22
23
  import * as Capability from './capability';
23
24
  import * as CapabilityManager from './capability-manager';
24
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);
25
77
 
26
78
  /**
27
79
  * Identifier denoting a Manager.
@@ -29,12 +81,54 @@ import * as Plugin from './plugin';
29
81
  export const ManagerTypeId: unique symbol = Symbol.for('@dxos/app-framework/Manager');
30
82
  export type ManagerTypeId = typeof ManagerTypeId;
31
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
+
32
99
  export type ManagerOptions = {
33
- pluginLoader: (id: string) => Effect.Effect<Plugin.Plugin, Error>;
100
+ pluginLoader: (id: string) => Effect.Effect<LoadedPlugin, Error>;
34
101
  plugins?: Plugin.Plugin[];
35
102
  core?: string[];
36
103
  enabled?: string[];
37
104
  registry?: Registry.Registry;
105
+ /**
106
+ * Backend for the plugin registry catalog. When omitted the manager exposes a
107
+ * no-op `pluginRegistry` (empty list, no versions endpoint). Implementations
108
+ * live in app-framework alongside the interface (e.g.
109
+ * `EdgeRegistryPluginProvider`); the host app instantiates one and passes it in.
110
+ */
111
+ pluginRegistryProvider?: PluginRegistry.PluginProvider;
112
+ /**
113
+ * Hook called when a plugin is removed via {@link PluginManager.remove}. Used by the
114
+ * host app to clean up persisted state (e.g. evict offline-cached plugin assets).
115
+ * Failures are logged and swallowed; removal still succeeds even if the hook fails.
116
+ */
117
+ onRemove?: (id: string) => Effect.Effect<void, unknown>;
118
+ /**
119
+ * Maximum time allowed for a lazy plugin's dynamic `import()` to resolve.
120
+ * Plugins that exceed this are flagged on the {@link PluginManager.failed}
121
+ * atom and auto-disabled so a stuck remote host can't stall app boot.
122
+ * Defaults to 30 seconds; pass `Duration.infinity` to disable.
123
+ */
124
+ loadTimeout?: Duration.DurationInput;
125
+ /**
126
+ * Maximum time allowed for a single module's `activate()` Effect to settle.
127
+ * Modules that exceed this fail with {@link PluginTimeoutError}; the owning
128
+ * plugin is recorded on `failed` and auto-disabled. Defaults to 30 seconds;
129
+ * pass `Duration.infinity` to disable.
130
+ */
131
+ activationTimeout?: Duration.DurationInput;
38
132
  };
39
133
 
40
134
  export type ActivationMessage = {
@@ -53,6 +147,13 @@ export interface PluginManager {
53
147
  readonly activation: PubSub.PubSub<ActivationMessage>;
54
148
  readonly capabilities: CapabilityManager.CapabilityManager;
55
149
  readonly registry: Registry.Registry;
150
+ /**
151
+ * Cached registry catalog state plus pass-throughs for `listVersions` /
152
+ * `getPlugin`. Always present — the host supplies a `pluginRegistryProvider`
153
+ * via {@link ManagerOptions} for real backends, or it falls back to a no-op
154
+ * implementation that yields an empty catalog.
155
+ */
156
+ readonly pluginRegistry: PluginRegistry.Manager;
56
157
 
57
158
  readonly plugins: Atom.Atom<readonly Plugin.Plugin[]>;
58
159
  readonly core: Atom.Atom<readonly string[]>;
@@ -61,6 +162,19 @@ export interface PluginManager {
61
162
  readonly active: Atom.Atom<readonly string[]>;
62
163
  readonly eventsFired: Atom.Atom<readonly string[]>;
63
164
  readonly pendingReset: Atom.Atom<readonly string[]>;
165
+ /**
166
+ * Plugins that failed to load or activate. Subscribers (e.g. the registry
167
+ * UI) can use this to flag unhealthy entries; a plugin id appears here at
168
+ * most once with its most recent failure.
169
+ */
170
+ readonly failed: Atom.Atom<readonly PluginFailure[]>;
171
+ /**
172
+ * Ids of currently-registered plugins that came from a dev source (loaded
173
+ * via {@link LoadedPlugin} with `dev: true`). Subscribers can use this to
174
+ * badge dev-overridden plugins or to derive the id of the active dev plugin
175
+ * for an "uninstall dev plugin" affordance.
176
+ */
177
+ readonly devPluginIds: Atom.Atom<readonly string[]>;
64
178
 
65
179
  getPlugins(): readonly Plugin.Plugin[];
66
180
  getCore(): readonly string[];
@@ -69,6 +183,14 @@ export interface PluginManager {
69
183
  getActive(): readonly string[];
70
184
  getEventsFired(): readonly string[];
71
185
  getPendingReset(): readonly string[];
186
+ getFailed(): readonly PluginFailure[];
187
+ getDevPluginIds(): readonly string[];
188
+
189
+ /**
190
+ * Clears the failure record for a plugin so it can be retried. Returns
191
+ * whether a failure record existed and was removed.
192
+ */
193
+ clearFailure(id: string): boolean;
72
194
 
73
195
  /**
74
196
  * Loads a plugin via the plugin loader and registers it without enabling it.
@@ -77,7 +199,7 @@ export interface PluginManager {
77
199
  */
78
200
  add(id: string): Effect.Effect<Plugin.Plugin, Error>;
79
201
  enable(id: string): Effect.Effect<boolean, Error>;
80
- remove(id: string): boolean;
202
+ remove(id: string): Effect.Effect<boolean, Error>;
81
203
  disable(id: string): Effect.Effect<boolean, Error>;
82
204
  // TODO(wittjosiah): Improve error typing.
83
205
  activate(
@@ -110,6 +232,7 @@ class ManagerImpl implements PluginManager {
110
232
  readonly activation = Effect.runSync(PubSub.unbounded<ActivationMessage>());
111
233
  readonly capabilities: CapabilityManager.CapabilityManager;
112
234
  readonly registry: Registry.Registry;
235
+ readonly pluginRegistry: PluginRegistry.Manager;
113
236
 
114
237
  private readonly _pluginsAtom: Atom.Writable<Plugin.Plugin[]>;
115
238
  private readonly _coreAtom: Atom.Writable<string[]>;
@@ -118,15 +241,41 @@ class ManagerImpl implements PluginManager {
118
241
  private readonly _activeAtom: Atom.Writable<string[]>;
119
242
  private readonly _eventsFiredAtom: Atom.Writable<string[]>;
120
243
  private readonly _pendingResetAtom: Atom.Writable<string[]>;
244
+ private readonly _failedAtom: Atom.Writable<PluginFailure[]>;
121
245
  private readonly _pluginLoader: ManagerOptions['pluginLoader'];
246
+ private readonly _onRemove: ManagerOptions['onRemove'];
247
+ private readonly _loadTimeout: Duration.DurationInput;
248
+ private readonly _activationTimeout: Duration.DurationInput;
122
249
  private readonly _capabilities = new Map<string, Capability.Any[]>();
123
250
  private readonly _moduleMemoMap = new Map<Plugin.PluginModule['id'], Deferred.Deferred<Capability.Any[], Error>>();
124
251
  private readonly _moduleSemaphores = new Map<Plugin.PluginModule['id'], Effect.Semaphore>();
252
+ // Coalesces concurrent `_resolveLazyPlugin` calls per plugin id. Without
253
+ // this, two callers entering `enable(id)` before the swap completes would
254
+ // each invoke `mod.default(options)` and produce distinct module objects,
255
+ // defeating `_addModule`'s reference-equality dedupe and racing the
256
+ // `_pluginsAtom` swap.
257
+ private readonly _resolvingPlugins = new Map<string, Deferred.Deferred<Plugin.Plugin, Plugin.LazyPluginError>>();
258
+ // Tracks dev-source plugins (loaded via a Vite dev server) keyed by id.
259
+ // When `shadow` is present, the entry has displaced an existing plugin —
260
+ // `remove` reinstates it and re-enables iff `wasEnabled`. Entries without a
261
+ // shadow are dev plugins with no underlying registry/builtin to restore.
262
+ // The atom mirrors the map's keys for UI subscribers (they don't need the
263
+ // shadow internals); the two stay in sync via {@link _markDev}/{@link _unmarkDev}.
264
+ private readonly _devPlugins = new Map<string, { shadow?: { plugin: Plugin.Plugin; wasEnabled: boolean } }>();
265
+ private readonly _devPluginIdsAtom: Atom.Writable<string[]>;
125
266
  private readonly _activatingEvents = Effect.runSync(Ref.make<string[]>([]));
126
267
  private readonly _activatingModules = Effect.runSync(Ref.make<string[]>([]));
127
268
  private readonly _inFlightFibers = Effect.runSync(Ref.make<Array<Fiber.Fiber<unknown, unknown>>>([]));
128
269
  private readonly _shutdownSemaphore = Effect.runSync(Effect.makeSemaphore(1));
129
270
  private readonly _shuttingDown = Effect.runSync(Ref.make(false));
271
+ // Tracks the constructor-launched core/enabled `enable()` calls so that
272
+ // `activate` can wait for module registration before dispatching events.
273
+ // Lazy plugins make `enable` asynchronous (a dynamic `import()` happens
274
+ // inside it), so without this synchronization an `activate` triggered
275
+ // immediately after `make` could fire on an empty module set. Failures
276
+ // are wrapped in `PluginInitializationError` so awaiters get a tagged
277
+ // error rather than the wide `Error` produced by the underlying chain.
278
+ private readonly _initialization = Effect.runSync(Deferred.make<void, PluginInitializationError>());
130
279
 
131
280
  constructor({
132
281
  pluginLoader,
@@ -134,13 +283,21 @@ class ManagerImpl implements PluginManager {
134
283
  core = plugins.map(({ meta }) => meta.id),
135
284
  enabled = [],
136
285
  registry,
286
+ pluginRegistryProvider,
287
+ onRemove,
288
+ loadTimeout = DEFAULT_LOAD_TIMEOUT,
289
+ activationTimeout = DEFAULT_ACTIVATION_TIMEOUT,
137
290
  }: ManagerOptions) {
138
291
  this.registry = registry ?? Registry.make();
139
292
  this.capabilities = CapabilityManager.make({
140
293
  registry: this.registry,
141
294
  });
295
+ this.pluginRegistry = new PluginRegistry.Manager(pluginRegistryProvider, this.registry);
142
296
 
143
297
  this._pluginLoader = pluginLoader;
298
+ this._onRemove = onRemove;
299
+ this._loadTimeout = loadTimeout;
300
+ this._activationTimeout = activationTimeout;
144
301
  this._pluginsAtom = Atom.make(plugins).pipe(Atom.keepAlive);
145
302
  this._coreAtom = Atom.make(core).pipe(Atom.keepAlive);
146
303
  this._enabledAtom = Atom.make(enabled).pipe(Atom.keepAlive);
@@ -148,8 +305,22 @@ class ManagerImpl implements PluginManager {
148
305
  this._activeAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);
149
306
  this._eventsFiredAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);
150
307
  this._pendingResetAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);
308
+ this._failedAtom = Atom.make<PluginFailure[]>([]).pipe(Atom.keepAlive);
309
+ this._devPluginIdsAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);
151
310
  plugins.forEach((plugin) => this._addPlugin(plugin));
152
- void Effect.all([...core, ...enabled].map((id) => this.enable(id))).pipe(runAndForwardErrors);
311
+ // Dedupe before mapping to `enable` — `core` and `enabled` may overlap (an
312
+ // app-supplied plugin can be in both), and concurrent `enable(id)` calls
313
+ // for the same id are not idempotent (each would re-run the lazy resolve
314
+ // and double-register modules). `new Set([...])` preserves first-seen
315
+ // order which matches the natural core-before-enabled precedence.
316
+ const initialIds = [...new Set([...core, ...enabled])];
317
+ void Effect.all(initialIds.map((id) => this.enable(id)))
318
+ .pipe(
319
+ Effect.mapError((cause) => new PluginInitializationError({ cause })),
320
+ Effect.tap(() => Deferred.succeed(this._initialization, undefined)),
321
+ Effect.tapErrorCause((cause) => Deferred.failCause(this._initialization, cause)),
322
+ )
323
+ .pipe(runAndForwardErrors);
153
324
  }
154
325
 
155
326
  get plugins(): Atom.Atom<readonly Plugin.Plugin[]> {
@@ -195,6 +366,20 @@ class ManagerImpl implements PluginManager {
195
366
  return this._pendingResetAtom;
196
367
  }
197
368
 
369
+ /**
370
+ * Plugins that failed to load or activate.
371
+ */
372
+ get failed(): Atom.Atom<readonly PluginFailure[]> {
373
+ return this._failedAtom;
374
+ }
375
+
376
+ /**
377
+ * Ids of currently-registered plugins that came from a dev source.
378
+ */
379
+ get devPluginIds(): Atom.Atom<readonly string[]> {
380
+ return this._devPluginIdsAtom;
381
+ }
382
+
198
383
  getPlugins(): readonly Plugin.Plugin[] {
199
384
  return this._get(this._pluginsAtom);
200
385
  }
@@ -223,6 +408,48 @@ class ManagerImpl implements PluginManager {
223
408
  return this._get(this._pendingResetAtom);
224
409
  }
225
410
 
411
+ getFailed(): readonly PluginFailure[] {
412
+ return this._get(this._failedAtom);
413
+ }
414
+
415
+ getDevPluginIds(): readonly string[] {
416
+ return this._get(this._devPluginIdsAtom);
417
+ }
418
+
419
+ /**
420
+ * Marks `id` as dev-sourced. If the plugin displaced an existing one, pass
421
+ * the shadow snapshot so `remove` can restore it. Repeat calls (e.g. a dev
422
+ * plugin reload) preserve the original shadow target — restoration always
423
+ * unwinds back to the real underlying plugin, never an intermediate dev build.
424
+ */
425
+ private _markDev(id: string, shadow?: { plugin: Plugin.Plugin; wasEnabled: boolean }): void {
426
+ if (this._devPlugins.has(id)) {
427
+ return;
428
+ }
429
+ this._devPlugins.set(id, { shadow });
430
+ this._update(this._devPluginIdsAtom, (ids) => (ids.includes(id) ? ids : [...ids, id]));
431
+ }
432
+
433
+ /** Drops the dev-plugin entry and returns its shadow data (if any) for restoration. */
434
+ private _unmarkDev(id: string): { plugin: Plugin.Plugin; wasEnabled: boolean } | undefined {
435
+ const entry = this._devPlugins.get(id);
436
+ this._devPlugins.delete(id);
437
+ this._update(this._devPluginIdsAtom, (ids) => ids.filter((existing) => existing !== id));
438
+ return entry?.shadow;
439
+ }
440
+
441
+ clearFailure(id: string): boolean {
442
+ const current = this._get(this._failedAtom);
443
+ if (!current.some((failure) => failure.id === id)) {
444
+ return false;
445
+ }
446
+ this._set(
447
+ this._failedAtom,
448
+ current.filter((failure) => failure.id !== id),
449
+ );
450
+ return true;
451
+ }
452
+
226
453
  /**
227
454
  * Adds a plugin to the manager via the plugin loader.
228
455
  * The plugin is registered but not enabled; call `enable` separately to activate it.
@@ -231,8 +458,31 @@ class ManagerImpl implements PluginManager {
231
458
  add(id: string): Effect.Effect<Plugin.Plugin, Error> {
232
459
  return Effect.gen(this, function* () {
233
460
  log('add plugin', { id });
234
- const plugin = yield* this._pluginLoader(id);
235
- this._addPlugin(plugin);
461
+ const { plugin, dev = false } = yield* this._pluginLoader(id);
462
+ const pluginId = plugin.meta.id;
463
+ const existing = this._getPlugin(pluginId);
464
+
465
+ if (dev && existing && existing !== plugin) {
466
+ // Shadow path: a plugin with this id is already registered (a builtin,
467
+ // a registry install, or a previous dev load). Disable it, stash it,
468
+ // and swap the dev plugin into the same id slot. The dialog will call
469
+ // `enable(pluginId)` next, which activates the dev plugin's modules.
470
+ // `_markDev` is a no-op when the id is already tracked, so a dev-plugin
471
+ // reload (after editing source) keeps the *original* shadow target —
472
+ // removal restores the real underlying plugin, not an intermediate build.
473
+ const wasEnabled = this._get(this._enabledAtom).includes(pluginId);
474
+ if (wasEnabled) {
475
+ yield* this.disable(pluginId);
476
+ }
477
+ this._markDev(pluginId, { plugin: existing, wasEnabled });
478
+ this._update(this._pluginsAtom, (plugins) => plugins.map((p) => (p.meta.id === pluginId ? plugin : p)));
479
+ } else {
480
+ this._addPlugin(plugin);
481
+ if (dev) {
482
+ this._markDev(pluginId);
483
+ }
484
+ }
485
+
236
486
  return plugin;
237
487
  });
238
488
  }
@@ -244,11 +494,17 @@ class ManagerImpl implements PluginManager {
244
494
  enable(id: string): Effect.Effect<boolean, Error> {
245
495
  return Effect.gen(this, function* () {
246
496
  log('enable plugin', { id });
247
- const plugin = this._getPlugin(id);
248
- if (!plugin) {
497
+ const stub = this._getPlugin(id);
498
+ if (!stub) {
249
499
  return false;
250
500
  }
251
501
 
502
+ // Clear any prior failure record so a retry starts from a clean slate.
503
+ // The failure stays on the atom only if this attempt also fails.
504
+ this.clearFailure(id);
505
+
506
+ const plugin = yield* this._resolveLazyPlugin(stub);
507
+
252
508
  this._update(this._enabledAtom, (enabled) => (enabled.includes(id) ? enabled : [...enabled, id]));
253
509
 
254
510
  plugin.modules.forEach((module) => {
@@ -266,19 +522,108 @@ class ManagerImpl implements PluginManager {
266
522
  });
267
523
  }
268
524
 
525
+ /**
526
+ * Resolves a lazy plugin stub (returned by {@link Plugin.lazy}) to its
527
+ * loaded form and swaps it into `_pluginsAtom`. Returns the input unchanged
528
+ * when the plugin is already resolved, so callers can `yield*` this
529
+ * unconditionally. The lazy stub carries `meta` synchronously but its
530
+ * `modules` list is empty until the loader resolves; the swap ensures
531
+ * subsequent enable/disable operations see the resolved plugin.
532
+ *
533
+ * Concurrent calls for the same id are coalesced via `_resolvingPlugins`:
534
+ * the first caller starts the resolution, every subsequent caller awaits
535
+ * the same `Deferred`. On failure we publish a `lazy:<id>` error message
536
+ * and skip the atom swap so the failure is observable to the activation
537
+ * subscriber and a retry can be attempted.
538
+ */
539
+ private _resolveLazyPlugin(plugin: Plugin.Plugin): Effect.Effect<Plugin.Plugin, Plugin.LazyPluginError> {
540
+ return Effect.gen(this, function* () {
541
+ if (!Plugin.isLazy(plugin)) {
542
+ return plugin;
543
+ }
544
+ const id = plugin.meta.id;
545
+
546
+ const existing = this._resolvingPlugins.get(id);
547
+ if (existing) {
548
+ return yield* Deferred.await(existing);
549
+ }
550
+ const deferred = yield* Deferred.make<Plugin.Plugin, Plugin.LazyPluginError>();
551
+ this._resolvingPlugins.set(id, deferred);
552
+
553
+ return yield* Effect.gen(this, function* () {
554
+ log('resolving lazy plugin', { id });
555
+ yield* PubSub.publish(this.activation, { event: '', state: 'activating', module: `lazy:${id}` });
556
+ const resolvedPlugin = yield* Plugin.resolveLazy(plugin).pipe(
557
+ // Cap how long a remote import can hang. Without this the host can
558
+ // sit on a pending dynamic `import()` indefinitely if the plugin's
559
+ // server is unreachable, which stalls every caller awaiting
560
+ // `enable(id)` and (transitively) the manager's initialization.
561
+ Effect.timeoutFail({
562
+ duration: this._loadTimeout,
563
+ onTimeout: () =>
564
+ new Plugin.LazyPluginError({
565
+ context: { id, reason: 'load-failed' },
566
+ cause: new PluginTimeoutError({ context: { id, phase: 'load' as PluginFailurePhase } }),
567
+ }),
568
+ }),
569
+ );
570
+ this._update(this._pluginsAtom, (plugins) => plugins.map((p) => (p.meta.id === id ? resolvedPlugin : p)));
571
+ yield* PubSub.publish(this.activation, { event: '', state: 'activated', module: `lazy:${id}` });
572
+ return resolvedPlugin;
573
+ }).pipe(
574
+ Effect.tapError((error) =>
575
+ Effect.gen(this, function* () {
576
+ yield* PubSub.publish(this.activation, { event: '', state: 'error', module: `lazy:${id}`, error });
577
+ this._recordFailure(id, 'load', error);
578
+ this._scheduleAutoDisable(id);
579
+ }),
580
+ ),
581
+ Effect.tap((value) => Deferred.succeed(deferred, value)),
582
+ Effect.tapErrorCause((cause) => Deferred.failCause(deferred, cause)),
583
+ Effect.ensuring(Effect.sync(() => this._resolvingPlugins.delete(id))),
584
+ );
585
+ });
586
+ }
587
+
269
588
  /**
270
589
  * Removes a plugin from the manager.
271
590
  * @param id The id of the plugin.
272
591
  */
273
- remove(id: string): boolean {
274
- log('remove plugin', { id });
275
- const result = this.disable(id);
276
- if (!result) {
277
- return false;
278
- }
592
+ remove(id: string): Effect.Effect<boolean, Error> {
593
+ return Effect.gen(this, function* () {
594
+ log('remove plugin', { id });
595
+ const wasDev = this._devPlugins.has(id);
596
+ const disabled = yield* this.disable(id);
597
+ if (!disabled) {
598
+ return false;
599
+ }
279
600
 
280
- this._removePlugin(id);
281
- return true;
601
+ this._removePlugin(id);
602
+ if (this._onRemove) {
603
+ this._runForkedFiber(
604
+ this._onRemove(id).pipe(
605
+ Effect.tapError((error) => Effect.sync(() => log.warn('plugin remove hook failed', { id, error }))),
606
+ Effect.ignore,
607
+ ),
608
+ );
609
+ }
610
+
611
+ // If a dev plugin was shadowing an existing plugin, reinstate the
612
+ // original now that the dev plugin is gone. Re-enable only if the
613
+ // original was enabled at shadow time — preserving the user's intent
614
+ // for plugins they had explicitly disabled before iterating on a dev
615
+ // build.
616
+ if (wasDev) {
617
+ const shadow = this._unmarkDev(id);
618
+ if (shadow) {
619
+ this._addPlugin(shadow.plugin);
620
+ if (shadow.wasEnabled) {
621
+ yield* this.enable(id);
622
+ }
623
+ }
624
+ }
625
+ return true;
626
+ });
282
627
  }
283
628
 
284
629
  /**
@@ -327,6 +672,12 @@ class ManagerImpl implements PluginManager {
327
672
  return false;
328
673
  }
329
674
 
675
+ // Wait for the constructor's core/enabled `enable()` chain — including
676
+ // any async dynamic imports for lazy plugins — to finish registering
677
+ // modules. Without this, dispatching to an empty module set is the
678
+ // observable symptom of the race.
679
+ yield* Deferred.await(this._initialization);
680
+
330
681
  return yield* Effect.withFiberRuntime<boolean, Error>((fiber) =>
331
682
  this._activateEvent(key, params, fiber).pipe(
332
683
  together(
@@ -446,6 +797,46 @@ class ManagerImpl implements PluginManager {
446
797
  return this._get(this._pluginsAtom).find((plugin) => plugin.meta.id === id);
447
798
  }
448
799
 
800
+ private _getPluginIdForModule(moduleId: string): string | undefined {
801
+ return this._get(this._pluginsAtom).find((plugin) => plugin.modules.some((module) => module.id === moduleId))?.meta
802
+ .id;
803
+ }
804
+
805
+ /**
806
+ * Records a failure for a plugin. Latest failure wins so the registry UI
807
+ * always sees the most recent reason. Walks the `cause` chain when checking
808
+ * for timeouts: lazy-load timeouts arrive wrapped in `LazyPluginError` (the
809
+ * timeout is the cause), but the operator-visible reason should still be
810
+ * `'timeout'`.
811
+ */
812
+ private _recordFailure(id: string, phase: PluginFailurePhase, error: Error): void {
813
+ const reason: PluginFailureReason = isTimeoutCause(error) ? 'timeout' : 'error';
814
+ const failure: PluginFailure = { id, phase, reason, error, timestamp: Date.now() };
815
+ log.warn('plugin failed', { id, phase, reason, error: error.message });
816
+ this._update(this._failedAtom, (current) => [...current.filter((entry) => entry.id !== id), failure]);
817
+ }
818
+
819
+ /**
820
+ * Fire-and-forget disable of a failed plugin. Forked because a failure can
821
+ * happen mid-activation chain — yielding a `disable` inline would deadlock
822
+ * on the shared semaphores. Core plugins are skipped (the host opted into
823
+ * them being non-removable; the failure record is enough signal).
824
+ */
825
+ private _scheduleAutoDisable(id: string): void {
826
+ if (this._get(this._coreAtom).includes(id)) {
827
+ return;
828
+ }
829
+ if (!this._get(this._enabledAtom).includes(id)) {
830
+ return;
831
+ }
832
+ this._runForkedFiber(
833
+ this.disable(id).pipe(
834
+ Effect.tapError((error) => Effect.sync(() => log.warn('auto-disable failed', { id, error }))),
835
+ Effect.ignore,
836
+ ),
837
+ );
838
+ }
839
+
449
840
  private _getActiveModules(): Plugin.PluginModule[] {
450
841
  const active = this._get(this._activeAtom);
451
842
  return this._get(this._modulesAtom).filter((module) => active.includes(module.id));
@@ -517,6 +908,18 @@ class ManagerImpl implements PluginManager {
517
908
  return Ref.update(ref, (fibers) => fibers.filter((trackedFiber) => trackedFiber !== fiber));
518
909
  }
519
910
 
911
+ /**
912
+ * Spawns an effect on the default runtime and registers the resulting fiber in
913
+ * `_inFlightFibers` so {@link shutdown} can interrupt it. Used from sync entry
914
+ * points like {@link remove} where there is no enclosing Effect to fork from;
915
+ * inside an Effect chain prefer the existing track/await/untrack pattern.
916
+ */
917
+ private _runForkedFiber<E>(effect: Effect.Effect<void, E>): void {
918
+ const fiber = Effect.runFork(effect);
919
+ Effect.runSync(this._trackFiber(this._inFlightFibers, fiber));
920
+ Effect.runFork(Fiber.await(fiber).pipe(Effect.andThen(() => this._untrackFiber(this._inFlightFibers, fiber))));
921
+ }
922
+
520
923
  //
521
924
  // Registration helpers
522
925
  //
@@ -708,7 +1111,7 @@ class ManagerImpl implements PluginManager {
708
1111
  ): Effect.Effect<Capability.Any[][], Error> {
709
1112
  return Function.pipe(
710
1113
  modules,
711
- Array.map((mod) => this._loadModule(mod)),
1114
+ Array.map((mod) => this._loadModule(mod, key)),
712
1115
  Effect.allWith({ concurrency: 'unbounded' }),
713
1116
  Effect.catchAll((error) => {
714
1117
  return Effect.gen(this, function* () {
@@ -747,7 +1150,14 @@ class ManagerImpl implements PluginManager {
747
1150
  return semaphore;
748
1151
  }
749
1152
 
750
- private _loadModule = (module: Plugin.PluginModule): Effect.Effect<Capability.Any[], Error> =>
1153
+ // `parentEvent` is the activation event that first triggered this module
1154
+ // load — included in `activating`/`activated` PubSub messages so subscribers
1155
+ // (e.g. the boot loader's status listener) can associate a module with its
1156
+ // triggering event in the trace. The same module may be referenced by
1157
+ // multiple events, but module loads are memoized via `_moduleMemoMap`, so
1158
+ // only the first event to need it will appear here; later events await the
1159
+ // cached deferred without re-publishing.
1160
+ private _loadModule = (module: Plugin.PluginModule, parentEvent: string): Effect.Effect<Capability.Any[], Error> =>
751
1161
  Effect.gen(this, function* () {
752
1162
  const semaphore = this._getModuleSemaphore(module.id);
753
1163
 
@@ -763,23 +1173,33 @@ class ManagerImpl implements PluginManager {
763
1173
  this._moduleMemoMap.set(module.id, deferred);
764
1174
 
765
1175
  const loadEffect = Effect.gen(this, function* () {
766
- log('loading module', { module: module.id });
1176
+ log('loading module', { module: module.id, parentEvent });
767
1177
  performance.mark(`module:${module.id}:start`);
768
- yield* PubSub.publish(this.activation, { event: '', state: 'activating', module: module.id });
769
- const [duration, capabilities] = yield* module
770
- .activate()
771
- .pipe(
772
- Effect.provideService(Capability.Service, this.capabilities),
773
- Effect.provideService(Plugin.Service, this),
774
- Effect.timed,
775
- );
1178
+ yield* PubSub.publish(this.activation, { event: parentEvent, state: 'activating', module: module.id });
1179
+ const pluginId = this._getPluginIdForModule(module.id);
1180
+ const [duration, capabilities] = yield* module.activate().pipe(
1181
+ Effect.provideService(Capability.Service, this.capabilities),
1182
+ Effect.provideService(Plugin.Service, this),
1183
+ // Cap activation so a single misbehaving module can't hold the
1184
+ // event chain open. On timeout the failure is recorded against
1185
+ // the plugin and surfaced as `PluginTimeoutError`.
1186
+ Effect.timeoutFail({
1187
+ duration: this._activationTimeout,
1188
+ onTimeout: () =>
1189
+ new PluginTimeoutError({
1190
+ context: { id: pluginId ?? module.id, module: module.id, phase: 'activation' as PluginFailurePhase },
1191
+ }),
1192
+ }),
1193
+ Effect.timed,
1194
+ );
776
1195
  const normalized = capabilities == null ? [] : Array.isArray(capabilities) ? capabilities : [capabilities];
777
1196
  const elapsed = Duration.toMillis(duration);
778
1197
  performance.mark(`module:${module.id}:end`);
779
1198
  performance.measure(`module:${module.id}`, `module:${module.id}:start`, `module:${module.id}:end`);
780
- yield* PubSub.publish(this.activation, { event: '', state: 'activated', module: module.id });
1199
+ yield* PubSub.publish(this.activation, { event: parentEvent, state: 'activated', module: module.id });
781
1200
  log('loaded module', {
782
1201
  module: module.id,
1202
+ parentEvent,
783
1203
  elapsed,
784
1204
  failed: false,
785
1205
  });
@@ -816,7 +1236,13 @@ class ManagerImpl implements PluginManager {
816
1236
  stack: error instanceof Error ? error.stack : undefined,
817
1237
  isDefect: !Cause.isFailure(cause),
818
1238
  });
819
- return Deferred.fail(deferred, error instanceof Error ? error : new Error(String(error)));
1239
+ const normalizedError = error instanceof Error ? error : new Error(String(error));
1240
+ const pluginId = this._getPluginIdForModule(module.id);
1241
+ if (pluginId !== undefined) {
1242
+ this._recordFailure(pluginId, 'activation', normalizedError);
1243
+ this._scheduleAutoDisable(pluginId);
1244
+ }
1245
+ return Deferred.fail(deferred, normalizedError);
820
1246
  }),
821
1247
  ),
822
1248
  );
@@ -877,6 +1303,22 @@ class ManagerImpl implements PluginManager {
877
1303
  */
878
1304
  export const make = (options: ManagerOptions): PluginManager => new ManagerImpl(options);
879
1305
 
1306
+ /**
1307
+ * True when `error` (or anything along its `cause` chain) is a
1308
+ * {@link PluginTimeoutError}. Lazy-load timeouts wrap the timeout inside
1309
+ * `LazyPluginError`, so a shallow check on the outer error misses them.
1310
+ * Bounded depth so a circular chain can't loop forever.
1311
+ */
1312
+ const isTimeoutCause = (error: unknown, depth = 0): boolean => {
1313
+ if (depth > 5 || !(error instanceof Error)) {
1314
+ return false;
1315
+ }
1316
+ if (PluginTimeoutError.is(error)) {
1317
+ return true;
1318
+ }
1319
+ return isTimeoutCause((error as Error & { cause?: unknown }).cause, depth + 1);
1320
+ };
1321
+
880
1322
  /**
881
1323
  * Runs an effect concurrently with another effect.
882
1324
  * If the first effect completes, the second effect is interrupted.