Skip to content

feat(opencode-plugin): support the OpenCode v2 plugin API - #5273

Closed
ttelfer wants to merge 1 commit into
volcengine:mainfrom
ttelfer:feat/opencode-v2-plugin
Closed

ttelfer wants to merge 1 commit into
volcengine:mainfrom
ttelfer:feat/opencode-v2-plugin

Conversation

@ttelfer

@ttelfer ttelfer commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Description

OpenCode 2 does not run v1 hook plugins. This keeps the existing server() entrypoint and adds setup() so @openviking/opencode-plugin works on OpenCode 1.18.29+ and OpenCode 2 without a top-level @opencode/plugin import.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Related to #5226

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Test update

Changes Made

  • Export { id, setup, server } from the OpenCode plugin. OpenCode 1 still calls server() / OpenVikingPlugin; OpenCode 2 calls setup().
  • Register the stdio MCP proxy through ctx.mcp.transform using the v2 local server schema (timeout is { startup, catalog, execution }, not a number).
  • Inject repo context, session profile, and recall into session context system text, not the persisted prompt.
  • Normalize v2 session events into the existing capture handler: session.created, session.deleted, session.compacted, session.execution.succeeded|interrupted|failed, and session.message.content.updated. User text is captured from the prompt hook.
  • Leave the installer writing "plugin"; OpenCode 2 normalizes that key to "plugins".

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • macOS
    • Linux
    • Windows
cd examples/opencode-plugin && npm run check && node --test tests/*.test.mjs
node --test examples/memory-plugin-shared/recall-session-wiring.test.mjs

Not yet exercised in a live OpenCode 2.0.x session. This Mac is still OpenCode 1.18.31; the v1 hook path was covered by the existing plugin tests.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Additional Notes

v1 session/recall/MCP proxy code is unchanged in behavior. The v2 adapter is the only new seam. Compaction commits both from the compaction hook and from session.compacted, matching the existing v1 double path.

OpenCode 2 does not run v1 hook plugins. Keep the existing server()
entrypoint and add setup() so one package serves both, adapting MCP,
recall, capture, and lifecycle events to the v2 shapes.

Refs volcengine#5226
@ZaynJarvis ZaynJarvis added the agent-plugins Agent harness and plugin integrations label Sep 22, 2026
error: data.error ?? data.message,
}]
}
if (type === "session.message.content.updated") {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1] Capture the assistant events emitted by OpenCode v2

I tested this PR with OpenCode 2.0.15 using a successful opencode run. The event stream emitted session.text.started, session.text.delta, and session.text.ended, but no session.message.content.updated. OpenViking persisted the user message but not the assistant reply. In an isolated copy of the PR, mapping session.text.ended to the existing message/part events made the reply persist, confirming the missing event mapping as the cause. Please handle the actual v2 text events and add a test using their real event shape; the same end-to-end check should cover tool results.

@yufeng201

Copy link
Copy Markdown
Collaborator

The v1/v2 entrypoint split and shared runtime look reasonable. The v2 event adapter needs another design pass, though: it currently assumes a complete session.message.content.updated snapshot, while the observed OpenCode 2.0.15 stream emits separate text lifecycle events. This is an event-model mismatch, not just a missing event name.

Please establish which v2 events are the source of truth for completed assistant text and tool results, how prompt and streamed events are deduplicated, and when a session is safe to flush. Then test those real event sequences end to end. The inline finding shows a concrete failure caused by the current assumption.

@t0saki t0saki mentioned this pull request Sep 23, 2026
14 of 21 tasks
@t0saki

t0saki commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Superseded by #5341. I preserved the original commit and authorship there, then added the v2.0.15 lifecycle, capture, injection, MCP, test, and documentation fixes. Thanks for the initial implementation.

@t0saki t0saki closed this Sep 23, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-plugins Agent harness and plugin integrations

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants