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'.
This commit is contained in:
2026-11-04 18:59:58 -08:00
parent 4a3e671aa1
commit 62bb2eb93c
2 changed files with 23 additions and 4 deletions
+8 -4
View File
@@ -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<Finding[]> {
})
}
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({
}
})
},
})
}