Skip to content

Commit ff8c115

Browse files
committed
feat: adapt to OpenCode v2 plugin API (>=1.17.10) with event/dispose hooks
1 parent 0b1dc74 commit ff8c115

4 files changed

Lines changed: 116 additions & 49 deletions

File tree

AGENTS.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,23 @@ npx @agentmemory/agentmemory (CLI + worker, ~15-30s startup)
3737
- **Engine version pin**: agentmemory pins iii-engine to v0.11.2 (v0.11.6+ has incompatible sandbox model).
3838
- **Windows**: no binary auto-download; Docker fallback needed.
3939

40-
## Plugin API Compliance
40+
## Plugin API Compliance (v2)
4141

42-
Per [OpenCode Plugin API](https://opencode.ai/docs/en/plugins/)`@opencode-ai/plugin` v1.15+ (Hooks interface):
42+
Per [OpenCode Plugin API v2](https://opencode.ai/docs/en/plugins/)`@opencode-ai/plugin` >=1.17.10 (Effect + Promise plugins):
4343

44+
- **`Plugin` signature**: `(input: PluginInput, options?: PluginOptions) => Promise<Hooks>`. `PluginInput` includes `client`, `project`, `directory`, `worktree`, `serverUrl`, etc.
4445
- **`config` hook**: called on every config load. Guard with `if (!timer)` for once-only init. Signature: `config?: (input: Config) => Promise<void>`.
45-
- **`event` hook**: subscribe to lifecycle events including `server.instance.disposed`. Use for cleanup.
46-
- **`timer.unref()`**: mark the health-check interval as non-blocking so it never prevents the Node process from exiting. Replaces the need for a `dispose` hook.
47-
- **`dispose` does NOT exist**: the OpenCode `Hooks` interface has no `dispose` property. DO NOT return a `dispose` property from the plugin function — it will never be called. Use `timer.unref()` + the `event` hook instead.
46+
- **`event` hook**: subscribe to lifecycle events including `server.instance.disposed`. Use for cleanup alongside `timer.unref()`.
47+
- **`dispose` hook**: **NEW in v1.17.10+**. Called when the server shuts down. Use for deterministic cleanup.
48+
- **`timer.unref()`**: mark the health-check interval as non-blocking so it never prevents the Node process from exiting.
4849
- **`client.app.log()`**: Use for structured logging, not `console.error`.
4950

5051
## Conventions
5152

5253
- TypeScript strict — no `any`, no `@ts-ignore`
5354
- Single export: `AgentmemoryLauncherPlugin: Plugin`
5455
- Stateless — process supervision via `child.unref()`, no file I/O
55-
- Runtime dependency: only `@opencode-ai/plugin` (devDeps in `package.json`)
56+
- Runtime dependency: only `@opencode-ai/plugin` (>=1.17.10)
5657

5758
## CI/CD
5859

package-lock.json

Lines changed: 85 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)