Aiden Cline 2 месяцев назад
Родитель
Сommit
519d344470
2 измененных файлов с 15 добавлено и 0 удалено
  1. 14 0
      packages/opencode/src/plugin/index.ts
  2. 1 0
      packages/plugin/src/index.ts

+ 14 - 0
packages/opencode/src/plugin/index.ts

@@ -244,6 +244,20 @@ export const layer = Layer.effect(
           }).pipe(Effect.ignore)
         }
 
+        yield* Effect.addFinalizer(() =>
+          Effect.forEach(
+            hooks,
+            (hook) =>
+              Effect.tryPromise({
+                try: () => Promise.resolve(hook.dispose?.()),
+                catch: (error) => {
+                  log.error("plugin dispose hook failed", { error })
+                },
+              }).pipe(Effect.ignore),
+            { discard: true },
+          ),
+        )
+
         // Subscribe to bus events, fiber interrupted when scope closes
         yield* (yield* bus.subscribeAll()).pipe(
           Stream.runForEach((input) =>

+ 1 - 0
packages/plugin/src/index.ts

@@ -220,6 +220,7 @@ export type ProviderHook = {
 export type AuthOuathResult = AuthOAuthResult
 
 export interface Hooks {
+  dispose?: () => Promise<void>
   event?: (input: { event: Event }) => Promise<void>
   config?: (input: Config) => Promise<void>
   tool?: {