[Bug]: opencode plugin template fails on OpenCode 2.x — V2 loader requires { id, setup }, template exports legacy function
Summary
code-review-graph install --platform opencode (2.3.8) writes ~/.config/opencode/plugins/crg-plugin.ts from _opencode_plugin_content() in code_review_graph/skills.py. On OpenCode v2.0.7 the plugin fails on every startup and never runs.
Server log (~/.local/share/opencode/log/opencode.log):
message="failed to load plugin" target=.../crg-plugin.ts ref=err_230b6ff8 cause="Cause([Fail(PluginModule.LoadError: Plugin must export a default definition with an id and an effect or setup function. (cause: SchemaError(Expected object at [\"default\"])))])" role=serveropencode plugin list shows the entry with ID - and state failed.
Root cause
The template exports a bare function (export default (app: any) => { app.on(...) }) using the removed app.on EventEmitter API. The V2 loader requires the default export to be an object with an id and a setup (or effect) function (Plugin.define({ id, setup })), so schema validation rejects the module before any hook runs.
Related: #947 covers the app.on is not a function failure; #949 ports the template to the V1 returned-hooks shape (export default CodeReviewGraphPlugin where the default is still a function). A function default export still fails the V2 loader with the SchemaError(Expected object at ["default"]) above, so #949 does not fix OpenCode 2.x.
Secondary bug in the same template (also noted in #947): the run($, cmd) helper interpolates a full command string as one Bun template ($\${cmd}`), which Bun escapes into a single executable name. Commands must be literal tagged templates or use node:child_process`.
Expected
Template emits a V2 plugin:
import { Plugin } from "@opencode/plugin"
export default Plugin.define({
id: "code-review-graph",
async setup(ctx) {
// session.created via ctx.event.subscribe + `code-review-graph status`
// file edits via ctx.tool.hook("execute.after") on edit/write/patch + `update --skip-flows`
// git commit via ctx.tool.hook("execute.before") + `detect-changes --brief`
},
})using node:child_process for subprocesses (no Bun $ string interpolation), scoped to the plugin instance directory, never blocking a commit.
Local verification
Rewrote the installed plugin to the shape above: bun build passes, opencode reload shows code-review-graph -> active in opencode plugin list and /api/plugin, and no new failed to load plugin entries appear. code-review-graph status itself works (graph present).
Proposed fix
Update _opencode_plugin_content() to emit the V2 shape and update tests/test_skills.py assertions (app.on( absent, Plugin.define, id: "code-review-graph", ctx.event.subscribe, ctx.tool.hook) accordingly. PR to follow against staging.
Source: tirth8205/code-review-graph