Skip to content

feat: migrate to OpenCode v2 plugin API - #4

Merged
ysm-dev merged 1 commit into
mainfrom
migrate-v2
Sep 14, 2026
Merged

ysm-dev merged 1 commit into
mainfrom
migrate-v2

Conversation

@ysm-dev

@ysm-dev ysm-dev commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • Migrate the plugin to @opencode/plugin with a stable Plugin.define() entrypoint and public v2 session/tool hooks.
  • Use ctx.generate.text() for translation so OpenCode owns provider selection, model variants, SQLite credentials, and OAuth refresh/persistence; remove the v1 auth-file readers and custom provider/OAuth adapters.
  • Preserve inline bilingual assistant replies through public HTTP response hooks for OpenAI Responses (including Codex), Chat Completions, Anthropic Messages, and Gemini. Both clients consume the normal persisted transcript.
  • Restore English-only model context using recorded translations, retain question-form translation, and persist activation/history records across restarts and forks.
  • Bump the plugin to 2.0.0, update configuration and packaging, and add native-parser tests plus an isolated real-host smoke test to CI.

Compatibility and behavior changes

  • Verified against OpenCode 2.0.3. The installed older opencode2 v0.0.0-dev-18322 did not pass the host smoke test.
  • Configure plugins using { package, options } entries. Local builds must point to the dist directory, not dist/index.js.
  • HTTP hooks disable the session WebSocket fast path for the location, including inactive translation sessions.
  • Unknown endpoints, non-SSE responses, and binary protocols such as Bedrock Converse retain English output with a server diagnostic.
  • Start a fresh v2 session when upgrading; v1 activation metadata and historical bilingual trailers are not migrated. OpenCode v1 users should remain on opencode-translate@1.

Verification

  • bun run check:ci
  • bun run typecheck
  • bun run knip
  • bun run test:coverage76 passing tests, 100% function coverage and 99.16% line coverage
  • bun run build
  • bun run test:package — install the packed artifact and exercise the v2 entrypoint
  • bun run test:host with OpenCode 2.0.3 — actual plugin activation, SQLite credential storage/rotation, bilingual persisted messages, English-only model requests, and restart recovery
  • git diff --check

The host test uses an isolated server/database and a local fake provider. Native stream tests use OpenCode’s actual protocol parsers. Browser and terminal visual rendering were not separately automated.

Reference: https://opencode.ai/v2/docs/build/plugins/migrate-v1

@ysm-dev
ysm-dev merged commit bd0eee5 into main Sep 14, 2026
2 checks passed
@ysm-dev
ysm-dev deleted the migrate-v2 branch September 14, 2026 03:41
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.

1 participant