feat(plugin): add promise plugin cleanup

This commit is contained in:
Dax Raad
2026-07-10 11:21:43 -04:00
parent c71701ddc6
commit 446783e035
6 changed files with 74 additions and 15 deletions
+9
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`.
+3 -1
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) {