Skip to content

Commit 519d344

Browse files
authored
feat(plugin): add dispose hook (anomalyco#29493)
1 parent a78605f commit 519d344

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

packages/opencode/src/plugin/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,20 @@ export const layer = Layer.effect(
244244
}).pipe(Effect.ignore)
245245
}
246246

247+
yield* Effect.addFinalizer(() =>
248+
Effect.forEach(
249+
hooks,
250+
(hook) =>
251+
Effect.tryPromise({
252+
try: () => Promise.resolve(hook.dispose?.()),
253+
catch: (error) => {
254+
log.error("plugin dispose hook failed", { error })
255+
},
256+
}).pipe(Effect.ignore),
257+
{ discard: true },
258+
),
259+
)
260+
247261
// Subscribe to bus events, fiber interrupted when scope closes
248262
yield* (yield* bus.subscribeAll()).pipe(
249263
Stream.runForEach((input) =>

packages/plugin/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export type ProviderHook = {
220220
export type AuthOuathResult = AuthOAuthResult
221221

222222
export interface Hooks {
223+
dispose?: () => Promise<void>
223224
event?: (input: { event: Event }) => Promise<void>
224225
config?: (input: Config) => Promise<void>
225226
tool?: {

0 commit comments

Comments
 (0)