Files
ollama-plagin-swap/examples
Andrew Emelyaneko d25aa7a686 Port OpenCode plugins to the V2 plugin API (2.2.5)
OpenCode 2.x uses a new plugin API; V1 plugins do not load at all. Both
example plugins are rewritten as `export default { id, setup }`.

Fixes, in order of severity:

- Default export with id/setup instead of a named `export const XPlugin`,
  which the V2 loader rejects with "Plugin must export a default definition
  with an id and an effect or setup function".
- Drop `client.app.log`: the V2 context has no client and no logging API.
  Poll results go to ~/.local/state/ollama-plagin-swap/client.log and to the
  console. A file log is required because the managed background service
  sends stdout to /dev/null.
- Replace the `server.connected` trigger with an immediate poll in `setup`;
  V2 never delivers that event to in-process plugins.
- Replace the `session.deleted` interval teardown with a cleanup function
  returned from `setup`, and unref the timer so monitoring never keeps the
  server alive.
- Use `ctx.location.directory` instead of `ctx.directory`.
- Read opencode.jsonc as well as opencode.json when inferring controls from
  providers, stripping comments and trailing commas; provider inference
  previously failed silently on JSONC configs.
- Switch from require() to ESM imports.
- TypeScript variant: import types from `@opencode/plugin`, not
  `@opencode-ai/plugin`; register tools via `ctx.tool.transform` with JSON
  Schema and return `{ content }` from executors.
- Give the tool variant the id `ollama-plagin-swap.tools`, since reusing
  `ollama-plagin-swap` makes OpenCode fail it with "Duplicate plugin ID".

Verified on a live OpenCode 2.2.5 server: both variants report `active` via
/api/plugin and the poller writes swap status every interval.
2026-11-02 14:27:37 +03:00
..