From 519d3444701341f64e4fa20702a15508bf9830af Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Tue, 26 May 2026 21:21:53 -0500 Subject: [PATCH] feat(plugin): add dispose hook (#29493) --- packages/opencode/src/plugin/index.ts | 14 ++++++++++++++ packages/plugin/src/index.ts | 1 + 2 files changed, 15 insertions(+) diff --git a/packages/opencode/src/plugin/index.ts b/packages/opencode/src/plugin/index.ts index e59fefe080..793a072b29 100644 --- a/packages/opencode/src/plugin/index.ts +++ b/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) => diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index 6156477be2..3c710d076a 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -220,6 +220,7 @@ export type ProviderHook = { export type AuthOuathResult = AuthOAuthResult export interface Hooks { + dispose?: () => Promise event?: (input: { event: Event }) => Promise config?: (input: Config) => Promise tool?: {