Repository navigation
Description
I'd like revdiff's OpenCode integration to support OpenCode v2. The current integration under plugins/opencode/ uses the v1 plugin and custom-tool APIs, which need to be ported for v2.
References:
Migration considerations
The integration currently includes a revdiff tool, a /revdiff command, and an automatic plan-review plugin.
The plan-review plugin exports an async function returning an event hook. On session.idle, it reads the last assistant message, checks whether it was produced in plan mode, launches revdiff, and sends annotations back to the session. V2 requires a new plugin entrypoint and explicit subscriptions, and the message-reading, plan-detection, and prompt-submission logic needs to be checked against the new server API and lifecycle contracts.
The custom tool also uses the v1 tool() helper. V2 documents tool registration through ctx.tool.transform, with JSON Schema inputs and structured results. Existing Markdown command definitions remain supported, so the /revdiff command may need little change once its underlying tool is available.
There is also a routing consideration beyond the API changes: v2 uses a shared background server by default, including for tool execution. The existing launchers rely on terminal-specific environment variables to open the overlay in the correct pane. The server's environment may not identify the client that requested the review.
A CLI plugin may be a better fit for launching the interactive review in the user's terminal. Preserving the agent-callable tool would also require defining how a server-side request reaches the appropriate CLI client and returns annotations to the originating session.
Expected behavior
- Support manual diff review through
/revdiffand the agent-callablerevdifftool, preserving the existing ref, staged, and only options. - Automatically review completed plans and return annotations to the originating session for revision in plan mode.
- Open reviews in the correct terminal pane and project directory when multiple OpenCode clients share a server.
- Avoid duplicate reviews and unintended launches for unrelated sessions or subagents.
- Preserve exit-code handling: 0 for a clean exit, 10 for success with annotations, and other nonzero statuses as failures.
- Handle cancellation and plugin cleanup without leaving review processes or temporary files behind.
- Update installation instructions and tests for the supported v2 integration.
- Installer checks OpenCode version and installs appropriate plugin + tool + command.
- Existing v1 integration remains intact
Contribution
I'd be happy to try implementing this and submit a PR. Before starting, I'd appreciate feedback on the preferred approach
Activity
umputun commentedon Sep 28, 2026
the premise is right: v2 does not run v1 plugins, so on v2 the
revdifftool and the plan-review plugin never load, and/revdiffpoints the model at a tool that does not exist. A PR is welcome. My answers on the approach:v1 stays. npm
opencode-ai@latestis still 1.18.x, so the files inplugins/opencode/stay byte-identical and v2 goes in its own files.CLI plugin for both
/revdiffand plan review. The launchers pick the pane from the terminal env (TMUX,KITTY_WINDOW_ID,AGTERM_SESSION_IDand the rest). The shared server keeps the env of whichever client started it, and a tool call carries no client identity, so a server-side launch opens the review in the wrong pane. A CLI plugin runs in the user's terminal, so the env is right andlaunch-revdiff.sh/launch-plan-review.shneed no changes.plan review can be in the same PR, with an explicit session rule. The CLI plugin sees every server event, so the PR has to define:
the agent-callable tool is not required for v2. If you want it, pls describe in the issue how a server-side call reaches the right client and gets the annotations back before writing code. Plugin RPC might carry it, but that is a small protocol with its own cancellation and no-client cases.
two things to settle here before writing code:
cli.jsonedits, npm resolution of@opencode/plugin, or a plain file copy. This decides whatsetup.shdoes.~/.config/opencode/. OpenCode v2 scansplugins/*.ts, fails to load the v1 plan-review file (packages/core/src/plugin/module.ts:111in v2.0.18), and skips the file pathsetup.shwrites intoopencode.json(config/plugin/source.ts:152). Both only log a warning, so the user ends up with no integration and no visible error. Upgrade and rollback should not leave broken v1 registrations behind or touch unrelated config.pls pin the
@opencode/pluginversion you tested against, and describe in the PR what you ran against a live v2 and which version. Tests here can't prove real loading or event order.LerikP commentedon Sep 29, 2026
Looks like context contains SessionID of the TUI, so agent can send event from server-side to open revdiff and proper client will filter it out and use it, but need to try it out
So far, it's not necessary, autodiscovery works just fine
Looks like there is no need to use npm to resolve packages Import
@opencode/plugin/tuidirectly. OpenCode resolves this import at runtime, so local CLI plugins do not need an absolute path to an OpenCode checkout.Will try to stick to this route
It can be in
plugins/plan-review/tui.js, so it would not be discovered by OpenCode v1, and old plugin will just be ignored as not-supported in v2, but I can include some setup parameter (e.g.--cleanto remove both plugin variants and opencode.json(c) entry before executing installation logic, so extra files are removed from plugins directory)umputun commentedon Sep 29, 2026
file copy with autodiscovery and a plugin directory are fine. OpenCode 1.18 only globs top-level
{plugin,plugins}/*.{ts,js}(config/plugin.ts) and v2 only picks up directories underplugins/(discovery.ts), so v1 never sees it. A few adjustments:/revdiffand plan review, so pls name it for the whole thing, e.g.plugins/revdiff/, and keep it.tslike the rest of the repo. Don't put aserver.*orindex.*file in it, the host resolves those beforetui(host.ts) and would try to load it as a server plugin.OPENCODE_CONFIG_DIR, then$XDG_CONFIG_HOME/opencode, so the v2 install should target that rather than the hardcoded~/.config/opencode.--clean. I was wrong earlier that a leftover v1 plugin only logs a warning. OpenCode v2 marks it failed and shows "1 plugin failed" in the home footer (footer.tsx). So the v2 install removesplugins/revdiff-plan-review.tsand the exact./plugins/revdiff-plan-review.tsentrysetup.shwrote toopencode.json, nothing else. Foropencode.jsoncprint a notice and leave it alone, jq can't round-trip comments. A v2 directory left behind after rolling back to v1 is inert, no need to handle it.commands/revdiff.md. A CLI slash command runs before server commands (prompt/index.tsx), but autocomplete lists both, and the md one asks for a tool that doesn't exist on v2. The v2 install should remove it.sessionIDidentifies a session, not a client. Two clients showing the same session both pass a sessionID filter and both open a review, and nothing defines what the tool call does when no CLI client is attached. Pls leave the tool out of this PR. If you want it later, write up the claim, return path, cancellation and no-client cases here first.one thing from my first comment is still open: one review per completed plan when two clients show the same session. It applies to automatic plan review regardless of the tool, so pls describe how the plugin decides which client owns the review before writing that part.
the links above are to the v2.0.19 source, not a live run, so the tested OpenCode version and what you ran against it still go in the PR.
LerikP commentedon Oct 2, 2026
For automatic plan review, I'd use a local-only, at-most-once ownership rule:
open(..., "wx")). The marker key is a hash of[sessionID, assistantMessageID].EEXISTand skip it.Markers live in a shared local state directory and contain no plan text. They remain across client restarts to prevent the same completed plan from reopening.
The trade-off is at most one review attempt, rather than guaranteed completion: if the winning client crashes or the launch fails after claiming, another client does not automatically take over. A newly generated plan has a new message ID and can be reviewed normally.
This coordinates clients on the same machine using the same state directory. It does not provide cross-machine coordination for clients attached to a remote shared server.
Would this local-only scope and at-most-once behavior be acceptable for the initial PR?
umputun commentedon Oct 2, 2026
yes, local-only and at-most-once are fine for the first PR, no takeover after a crash included. A few changes to the rule:
session.idleis deprecated in v2 (session-status-event.ts), the turn-completion event issession.execution.succeeded. Review live completions only, no sweep of older plans on load or session switch.message.sync.server.connectedand then live events only (event.ts). So a marker only has to outlive the race between two clients. Pls put them in a named directory, e.g.${XDG_STATE_HOME:-$HOME/.local/state}/revdiff/opencode-plan-review, and remove the ones older than a day when claiming.EEXISTmeans another client owns the review, any other error is shown and does not launch.data.session.root(id)returns the id itself when the session info is not loaded (data.ts), soroot(id) === idalone lets an unknown subagent through. Require loaded session info with noparentID.revdiffis on PATH before claiming, otherwise a client that can't open a review wins the marker and nobody else tries. Recheckui.router.current()after any await that comes before the claim.finally. The v1/tmp/revdiff-plan-<sessionID>.mdpath shouldn't carry over.the winner can be a client in a window the user is not looking at. That is fine as a documented limitation.
the links are to the v2.0.19 source, not a live run.
LerikP commentedon Oct 8, 2026
Can we close this as completed?
umputun commentedon Oct 8, 2026
yes, closing. OpenCode v2 support is in master via #370:
/revdiffand automatic plan review as a CLI plugin, with the installer picking v1 or v2.the agent-callable tool is the one item from the original list that is not there. If you want it, pls open a separate issue with the write-up first: how a client claims the call, how annotations get back, cancellation and the no-client case.
thx for the work on this.