Skip to content

feat!: migrate plugin to OpenCode V2 API (@opencode/plugin) - #4

Open
pedrovgp wants to merge 4 commits into
ErcinDedeoglu:mainfrom
pedrovgp:feat/opencode-v2-plugin
Open

pedrovgp wants to merge 4 commits into
ErcinDedeoglu:mainfrom
pedrovgp:feat/opencode-v2-plugin

Conversation

@pedrovgp

Copy link
Copy Markdown

Summary

OpenCode v2 rejects the V1 plugin shape, so oc-sync fails to load with:

PluginModule.LoadError: Plugin must export a default definition with an id and
an effect or setup function. (cause: SchemaError(Expected object at ["default"]))

This ports the plugin to the V2 API and updates the docs.

Root cause

oc-sync's default export is a V1 async function (export default async () => ...).
OpenCode v2 requires the default export to be an object { id, setup } (Promise API) or
{ id, effect } (Effect API).

Changes

  • src/plugin/plugin.ts: use Plugin.define({ id: 'oc-sync', setup }) from the official
    @opencode/plugin package; setup returns stopBackgroundSync as the cleanup function
    (runs on plugin unload), so background sync is disposed properly.
  • src/plugin/background-sync.ts: startFileWatcher / startIntervalSync are now idempotent
    (dispose any existing watcher/timer first) to avoid stacking on reload.
  • package.json: replace @opencode-ai/plugin with @opencode/plugin@^2.0.28; bump to
    0.2.0.
  • Docs: README, docs/LLM-INSTALL.md, docs/CONFIG.md, docs/DEV-SETUP.md use the V2
    plugins field, opencode plugin add / local directory install, and opencode service restart;
    docs/PUBLISH.md documents the 0.2.x (V2) / 0.1.x (V1) release lines; adds
    docs/UPGRADE-OPENCODE-V2.md.

Breaking change

V1 (function default export) and V2 ({ id, setup } object) module shapes are mutually
exclusive. 0.2.0 targets OpenCode v2 (2.0.28+); OpenCode 1.x users should stay on
oc-sync@0.1.x. Consider publishing 0.2.0 under the next dist-tag first.

Requirements

  • OpenCode v2 (2.0.28+)
  • @opencode/plugin matching the targeted OpenCode release

Testing

  • npm run check (typecheck + lint + format) and npm run build pass.
  • Built default export resolves to { id: 'oc-sync', setup }.
  • Loaded in OpenCode v2.0.28 via the global config plugins entry (absolute directory path);
    opencode plugin list shows oc-sync, and opencode-sync.log reports:
    Plugin starting... / Token loaded from: config file / File watcher started /
    Interval sync started (every 5 min) / Plugin ready / Initial sync complete: Already in sync.
  • No PluginModule.LoadError after load.

Notes

  • setup's cleanup is wired, but the exact reload path (config change vs service restart)
    should be confirmed when validating; a config change alone did not reload the plugin in testing —
    opencode service restart was required.
  • Follow-up: confirm the minimum OpenCode v2 version that ships @opencode/plugin v2 and pin docs
    accordingly.

OpenCode v2 requires a plugin default export shaped { id, effect } or
{ id, setup }. Wrap the plugin in define({ id: 'oc-sync', setup }) and drop
the (never-invoked) V1 cleanup return. Make watcher/interval start idempotent
so reloads do not stack timers. Pin @opencode-ai/plugin to ^1.19.0 and bump to
0.2.0 (breaking: V1 and V2 module shapes are mutually exclusive).
Switch from the V1 function export to Plugin.define({ id, setup }) from
@opencode/plugin (matching OpenCode 2.0.28) and return stopBackgroundSync as
the setup cleanup function, so background sync is disposed on unload. Make
watcher/interval start idempotent. Replace @opencode-ai/plugin with
@opencode/plugin ^2.0.28; bump to 0.2.0. Update the upgrade plan for the
native 'plugins' config field and local install layout.
README, LLM-INSTALL, CONFIG and DEV-SETUP now use the V2 'plugins' field,
opencode plugin add / local directory install, and 'opencode service restart'.
Add release-line notes to PUBLISH (0.2.x=V2, 0.1.x=V1) and link the upgrade
guide from README.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant