Skip to content

fix: migrate the plugin to the OpenCode V2 plugin API - #12

Merged
miguelmartens merged 1 commit into
mainfrom
fix/opencode-v2-plugin-api
Oct 10, 2026
Merged

miguelmartens merged 1 commit into
mainfrom
fix/opencode-v2-plugin-api

Conversation

@miguelmartens

Copy link
Copy Markdown
Owner

Summary

Port the plugin to the OpenCode V2 plugin API. V1 keeps working through the legacy entry point the migration guide documents.

 .opencode/plugins/
-├── caveman.mjs                  # V1 function export — V2 rejects it on load
-└── caveman-frontmatter.cjs
+└── caveman/
+    ├── index.mjs                # default: { id, setup(ctx), server() }
+    └── caveman-frontmatter.cjs

The directory form is required: V2 only discovers local plugins as <dir>/index.*, not bare files.

 setup(ctx)                       # V2
+  ctx.command.transform          <- config hook (commands)
+  ctx.skill.transform            <- config hook (skills dir)
+  ctx.agent.transform            <- config hook (upsert; V2 has no agent add)
+  session.hook("context")        <- experimental.chat.system.transform
+  session.hook("prompt")         <- chat.message
+  command execute                <- command.execute.before + template submit
 server()                         # V1 1.18.29+, unchanged behavior

Evidence

  • Before: opencode serve in a scratch project with the published @miguelmartens/opencode-caveman@1.0.2:
    failed to load plugin ... Plugin must export a default definition with an id and an effect or setup function.
  • After: same package entrypoint with this change: plugin active; all 4 commands, 4 skills, and 3 cavecrew agents registered; /caveman ultra persisted the level; stop caveman turned it off.
  • npm test 33/33 pass, npm run format:check clean.

Merge Danger

Door: two-way — reverting restores the V1 entrypoint.
Blast Radius: V1 below 1.18.29 no longer loads the package (function export becomes an object); 1.18.29+ works via server(). In V2, same-ID skills already present in ~/.agents/skills or project config override the bundled copies, because config sources apply after plugin transforms.

OpenCode V2 rejects the V1 function export with "Plugin must export a
default definition with an id and an effect or setup function", so the
plugin failed to load after the V2 upgrade.

- export a dual definition: `id` plus `setup(ctx)` for V2, `server()`
  for V1 1.18.29+, with the legacy hooks unchanged in behavior
- port registration to command/skill/agent transforms, system prompt
  injection to the session context hook, deactivation to the prompt
  hook, and `/caveman <level>` persistence into the command execute
- register skills without frontmatter and upsert the cavecrew
  subagents, appending an edit deny for the two read-only ones
- move the plugin to `.opencode/plugins/caveman/index.mjs`: V2 only
  discovers local plugins as directories with an index file
- update package entry points, the root opencode.json, docs, and tests
@miguelmartens
miguelmartens merged commit af7973e into main Oct 10, 2026
3 checks passed
@miguelmartens
miguelmartens deleted the fix/opencode-v2-plugin-api branch October 10, 2026 18:42
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