Skip to content

Commit ec18baa

Browse files
committed
fix: align plugin with @opencode-ai/plugin v1.15+ Hooks interface
1 parent 026eeee commit ec18baa

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

AGENTS.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ npx @agentmemory/agentmemory (CLI + worker, ~15-30s startup)
3939

4040
## Plugin API Compliance
4141

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

44-
- **`dispose` hook**: MANDATORY for plugins that start persistent resources (timers, processes). Must clear `setInterval`.
44+
- **`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.
4548
- **`client.app.log()`**: Use for structured logging, not `console.error`.
46-
- **`config` hook**: called on every config load. Guard with `if (!timer)` for once-only init.
4749

4850
## Conventions
4951

src/agentmemory-launcher.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Plugin } from "@opencode-ai/plugin";
1+
import type { Plugin, Config } from "@opencode-ai/plugin";
22
import { spawn } from "node:child_process";
33

44
// ── agentmemory-launcher ──
@@ -77,10 +77,11 @@ export const AgentmemoryLauncherPlugin: Plugin = async ({ client }) => {
7777
}
7878

7979
return {
80-
config: async () => {
80+
config: async (_config: Config) => {
8181
// first call only — start the health-check loop
8282
if (!timer) {
8383
timer = setInterval(checkAndRestart, HEALTH_INTERVAL);
84+
timer.unref();
8485
await log("info", "health-check loop started");
8586
}
8687

@@ -91,13 +92,5 @@ export const AgentmemoryLauncherPlugin: Plugin = async ({ client }) => {
9192
await log("error", `config hook check failed: ${String(err)}`);
9293
}
9394
},
94-
95-
dispose: async () => {
96-
if (timer) {
97-
clearInterval(timer);
98-
timer = null;
99-
}
100-
await log("info", "health-check loop stopped");
101-
},
10295
};
10396
};

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"module": "NodeNext",
55
"moduleResolution": "NodeNext",
66
"lib": ["ES2022"],
7+
"types": ["node"],
78
"outDir": "./dist",
89
"rootDir": "./src",
910
"declaration": true,

0 commit comments

Comments
 (0)