fix: load the claims plugin without the @opencode/plugin import #17

Merged
david merged 1 commits from fix/claims-plugin-load into main 2026-11-05 03:01:02 +00:00
Owner

Closes #16.

The plugin registered as failed with only "Plugin failed to load". The reference (err_7dd8e193) does not appear in the server log — grep across ~/.local/share/opencode/log/ finds nothing but my own command text, and there are no plugin errors at INFO level. So the log did not contain the underlying cause and could not be used to infer it.

How the cause was found

The running server exposes the plugin inventory at GET /api/plugin, which reports the real state per plugin. Controlled experiments, each a real directory the server loaded:

File Imports Result
index.js none active
index.ts none active
index.ts @opencode/plugin failed
index.ts @opencode-ai/plugin failed

That splits the problem cleanly: TypeScript compiles, the default export shape is accepted, the directory is discovered — only a bare package specifier fails.

Supporting evidence:

  • @opencode/plugin is not installed anywhere resolvable; the runtime defines it internally (as @opencode/plugin/tui) for its own use.
  • ~/.config/opencode/node_modules/@opencode-ai/plugin@1.2.27 is the V1 package, whose API has no Plugin.define.
  • node: builtins resolve normally.

Fix

Remove the import and export the definition object. Plugin.define is an identity function in the runtime (function Nl(t){return t}), so this is exactly equivalent — it is not a workaround that changes behaviour.

Verified: /api/plugin now reports active, id knox.claims.

The README records the constraint, since the official docs show the import and the next local plugin will hit the same wall.

Also in this PR

Experiment directories and their config entries were removed; plugins in ~/.config/opencode/opencode.json is back to the single claims entry.

Closes #16. The plugin registered as `failed` with only "Plugin failed to load". **The reference (`err_7dd8e193`) does not appear in the server log** — `grep` across `~/.local/share/opencode/log/` finds nothing but my own command text, and there are no plugin errors at INFO level. So the log did not contain the underlying cause and could not be used to infer it. ## How the cause was found The running server exposes the plugin inventory at `GET /api/plugin`, which reports the real state per plugin. Controlled experiments, each a real directory the server loaded: | File | Imports | Result | |---|---|---| | `index.js` | none | **active** | | `index.ts` | none | **active** | | `index.ts` | `@opencode/plugin` | **failed** | | `index.ts` | `@opencode-ai/plugin` | **failed** | That splits the problem cleanly: TypeScript compiles, the default export shape is accepted, the directory is discovered — only a **bare package specifier** fails. Supporting evidence: - `@opencode/plugin` is not installed anywhere resolvable; the runtime defines it internally (as `@opencode/plugin/tui`) for its own use. - `~/.config/opencode/node_modules/@opencode-ai/plugin@1.2.27` is the V1 package, whose API has no `Plugin.define`. - `node:` builtins resolve normally. ## Fix Remove the import and export the definition object. `Plugin.define` is an identity function in the runtime (`function Nl(t){return t}`), so this is exactly equivalent — it is not a workaround that changes behaviour. Verified: `/api/plugin` now reports `active`, id `knox.claims`. The README records the constraint, since the official docs show the import and the next local plugin will hit the same wall. ## Also in this PR Experiment directories and their config entries were removed; `plugins` in `~/.config/opencode/opencode.json` is back to the single `claims` entry.
david added 1 commit 2026-11-05 03:00:42 +00:00
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'.
david merged commit 0218d80019 into main 2026-11-05 03:01:02 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/knox#17