feat(plugin): add promise plugin cleanup

This commit is contained in:
Dax Raad 2026-07-10 11:21:43 -04:00
commit c867e66ab5
6 changed files with 74 additions and 15 deletions

View file

@ -25,6 +25,15 @@ export default Plugin.define({
```
Plugin setup registers hooks imperatively through each domain's `hook` method.
It may return a synchronous or asynchronous cleanup function. OpenCode awaits
the cleanup when the plugin is unloaded or replaced:
```ts
setup: async (ctx) => {
const timer = setInterval(refresh, 60_000)
return () => clearInterval(timer)
}
```
Configuration supplied for the plugin is available as `ctx.options`.

View file

@ -26,9 +26,11 @@ export interface Context {
readonly tool: ToolDomain
}
export type Cleanup = () => Promise<void> | void
export interface Plugin {
readonly id: string
readonly setup: (context: Context) => Promise<void> | void
readonly setup: (context: Context) => Promise<Cleanup | void> | Cleanup | void
}
export function define(plugin: Plugin) {