From 62bb2eb93c44886b1308362e6af00fab7d1ed3f4 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Wed, 4 Nov 2026 18:59:58 -0800 Subject: [PATCH] fix: load the claims plugin without the @opencode/plugin import (#16) A local plugin loaded by path cannot resolve bare package specifiers, so `import { Plugin } from "@opencode/plugin"` made the plugin fail with an opaque "Plugin failed to load". Isolated by experiment: index.js, no imports -> active index.ts, no imports -> active index.ts, @opencode/plugin -> failed index.ts, @opencode-ai/plugin -> failed So it was never the TypeScript, the default export or the hook. Plugin.define is an identity function in the runtime, so exporting the definition object directly is equivalent. Registered status is now 'active'. --- plugins/claims/README.md | 15 +++++++++++++++ plugins/claims/index.ts | 12 ++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/claims/README.md b/plugins/claims/README.md index cc0e16b..302f912 100644 --- a/plugins/claims/README.md +++ b/plugins/claims/README.md @@ -28,6 +28,21 @@ is appended as a system part for that request. All classification lives in the Go binary, so the plugin cannot drift from the tested implementation. +## Why there is no `@opencode/plugin` import + +The docs show `import { Plugin } from "@opencode/plugin"`, but a local plugin +loaded by path cannot resolve that bare specifier. Verified by experiment: + +| File | Imports | Result | +|---|---|---| +| `index.js` | none | active | +| `index.ts` | none | active | +| `index.ts` | `@opencode/plugin` | failed to load | +| `index.ts` | `@opencode-ai/plugin` | failed to load | + +`Plugin.define` is an identity function in the runtime, so exporting the +definition object directly is exactly equivalent. Only `node:` builtins resolve. + ## Enable ```jsonc diff --git a/plugins/claims/index.ts b/plugins/claims/index.ts index 9b3d663..70aa344 100644 --- a/plugins/claims/index.ts +++ b/plugins/claims/index.ts @@ -1,4 +1,8 @@ -import { Plugin } from "@opencode/plugin" +// NOTE: no import from "@opencode/plugin". A local plugin loaded by path cannot +// resolve that bare specifier — verified by experiment: identical code without +// the import loads, with it the plugin fails with "Plugin failed to load". +// `Plugin.define` is an identity function in the runtime, so exporting the +// definition object directly is equivalent. import { execFile } from "node:child_process" import { existsSync } from "node:fs" @@ -136,9 +140,9 @@ function check(turn: Turn): Promise { }) } -export default Plugin.define({ +export default { id: "knox.claims", - async setup(ctx) { + async setup(ctx: any) { await ctx.session.hook("context", async (event: any) => { try { const turn = splitTurns(event.messages as any[]) @@ -163,4 +167,4 @@ export default Plugin.define({ } }) }, -}) +}