Skip to content

fix(opencode): emit OpenCode 2.x plugin definition with id and setup - #1039

Open
ranokay wants to merge 2 commits into
tirth8205:stagingfrom
ranokay:fix/opencode-plugin-v2
Open

ranokay wants to merge 2 commits into
tirth8205:stagingfrom
ranokay:fix/opencode-plugin-v2

Conversation

@ranokay

@ranokay ranokay commented Sep 18, 2026

Copy link
Copy Markdown

Closes #1038.

Problem

The OpenCode installer template (_opencode_plugin_content() in code_review_graph/skills.py) exports a bare function using the removed app.on API. On OpenCode 2.x (verified v2.0.7) the loader rejects it before any hook runs:

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

opencode plugin list shows the entry with ID - / state failed. #947 covers the app.on failure; #949 ports the template to the V1 returned-hooks shape, but a function default export still fails the V2 loader, so 2.x stays broken.

The template's run($, cmd) helper has a second bug (also noted in #947): interpolating a full command string into Bun's $ template escapes it into a single executable name.

Fix

  • Template now emits a V2 definition: Plugin.define({ id: "code-review-graph", setup(ctx) {...} }) from @opencode/plugin.
  • session.created via ctx.event.subscribe + status (scoped to the plugin instance directory).
  • File edits via ctx.tool.hook("execute.after") on edit/write/patch + update --skip-flows (V2 has no file.edited hook).
  • Git-commit detection via ctx.tool.hook("execute.before") on bash/shell/execute + detect-changes --brief, never blocking.
  • Subprocesses via node:child_process execFile with argv arrays.
  • Tests updated to the V2 shape; CHANGELOG entry added.

Verification

  • uv run pytest tests/test_skills.py -q: 210 passed.
  • uv run ruff check code_review_graph/skills.py tests/test_skills.py: clean.
  • Generated template bun build --external @opencode/plugin: bundles clean.
  • Live run on OpenCode v2.0.7: after opencode reload, opencode plugin list and /api/plugin report code-review-graph -> active (was -/failed), no new failed to load plugin entries; code-review-graph status works against a real graph.

Copilot AI lite review requested due to automatic review settings September 18, 2026 06:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@tirth8205

Copy link
Copy Markdown
Owner

This no longer merges into staging. The one conflict is CHANGELOG.md, and the branch is 51 commits behind.

All of it is prose, so taking staging's text and re-applying your lines on top should be the whole job.

git fetch origin
git merge origin/staging
# resolve, then
uv run pytest tests/ -q
uv run ruff check code_review_graph/
uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
git push

I have not reviewed the change itself yet. That comes once it merges and the checks run against the merged state, since staging has moved a long way and the result is what matters.

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.

[Bug]: opencode plugin template fails on OpenCode 2.x — V2 loader requires { id, setup }, template exports legacy function

3 participants