Skip to content

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

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

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

Conversation

@ranokay

@ranokay ranokay commented Sep 18, 2026 •

Copy link
Copy Markdown

Linked issue

Closes #1038.

What & why

The installed OpenCode plugin now exports a V2 definition object with id and setup. The previous function export and app.on hooks fail the OpenCode 2.x loader. Session status uses ctx.event.subscribe; successful edits and pre-commit analysis use ctx.tool.hook. Subprocesses use execFile with argv arrays, fixing the Bun shell helper's whole-command escaping bug.

OpenCode 2.0.0–2.0.24 cannot resolve @opencode/plugin at runtime. The template keeps it type-only and exports the object directly:

-import { Plugin } from "@opencode/plugin"
-export default Plugin.define({ ... })
+import type { Plugin } from "@opencode/plugin"
+export default { ... } satisfies Parameters<typeof Plugin.define>[0]

The changelog entry is under [Unreleased]; released 2.3.9 still shipped the V1 template. The branch includes current staging through d72e8fb.

How it was tested

Both maintainer regressions failed before the fixes. Copied tests/test_opencode_v2_plugin_contract.py from review/pr-1039 and removed both xfail markers. Its runtime harness now loads the generated TypeScript without an @opencode/plugin stub, exercises the event/tool hooks and subprocess behavior, and checks install/reinstall/uninstall. The changelog test also requires the entry under [Unreleased].

uv run --locked --python 3.13 --extra dev pytest tests/test_opencode_v2_plugin_contract.py tests/test_skills.py -q
uv run --locked --python 3.13 --extra dev pytest tests/ --tb=short -q -m 'not browser and not upgrade' --cov=code_review_graph --cov-report=term --cov-fail-under=65
uv run --locked --python 3.13 --extra dev ruff check code_review_graph/ tests/test_skills.py tests/test_opencode_v2_plugin_contract.py
uv run --locked --python 3.13 --extra dev --with types-networkx mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
uv run --locked --python 3.13 --extra dev --with 'bandit[toml]' bandit -r code_review_graph/ -c pyproject.toml
  • Focused tests: 233 passed, including all 23 maintainer contract tests.
  • Full suite on signed commit ce577d676a1e233d7cd7169c2055fd4f1ef1de51: 5069 passed, 834 skipped, 46 deselected, 3 xfailed, 2 xpassed; 86.67% coverage.
  • Ruff: clean. Mypy: no issues in 77 source files. Bandit: no issues. Python/VS Code schema versions both equal 13.
  • Runtime harness used Node v26.11.1. Live OpenCode retesting is pending.

Checklist

  • Tests added for new functionality
  • Default test suite passes, with opt-in browser and upgrade suites excluded as in CI
  • Linting passes
  • Type checking passes
  • Python lines are at most 100 characters
  • Plugin docstring and changelog updated

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.

@tirth8205

Copy link
Copy Markdown
Owner

Thank you for this PR. I tested the plugin on real OpenCode 2.0.7, 2.0.24, 2.0.25 and 2.0.29. It works well on 2.0.25 and newer.

Before I can merge it, please fix these:

  1. The plugin does not load on OpenCode 2.0.0 to 2.0.24. This includes 2.0.7, the version in [Bug]: opencode plugin template fails on OpenCode 2.x — V2 loader requires { id, setup }, template exports legacy function #1038. The error is "Cannot find package '@opencode/plugin'". The cause is the line import { Plugin } from "@opencode/plugin" in code_review_graph/skills.py:2851. Please remove it or use import type. Plugin.define does nothing at runtime. Failing test: test_template_has_no_runtime_import_the_host_may_not_provide.

  2. Your CHANGELOG.md entry (line 94) merges into the released [2.3.9] section. Version 2.3.9 does not have this fix. Please move it under [Unreleased]. Failing test: test_changelog_credits_the_2x_template_only_to_releases_that_ship_it.

The failing tests are on the branch review/pr-1039 in this repo. You can copy them from there. If a test there is marked xfail, please remove that mark with your fix.

After you push the fix, I will test it again.

This branch has not been deployed

No deployments
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