Plan OpenCode V2 plugin API support
Context
OpenCode V2 is currently beta and intentionally does not load V1 plugins. The migration guide describes the new plugin shape (Plugin.define({ id, setup })) and runtime registration APIs: https://opencode.ai/v2/docs/migrate-v1
opencode-pty currently targets the V1 contract in src/plugin.ts, exporting an async plugin function with PluginContext / PluginResult and depending on @opencode-ai/plugin ^1.3.13.
This issue is a planning request, not an expectation that unstable V2 support ship immediately.
Suggested port plan
- Keep the current V1 entry point while V2 remains beta; add a separate V2 entry point/export.
- Replace the V1 async plugin export with a unique V2
idandsetup. - Register PTY tools through the V2 tool transform/registration surface, preserving existing schemas and descriptions.
- Map command handling and session notifications to V2 command/session APIs.
- Review process ownership and cleanup against V2 session interruption, service restart, and standalone/managed modes.
- Avoid sharing host-specific client calls between V1 and V2; keep the PTY/process core shared and adapters thin.
Compatibility checks
- Plugin appears in
opencode2 api get /api/plugin. - PTY creation, input, resize, output polling, and termination work in
opencode2 --standalone. - Managed service mode behaves the same as standalone mode.
- Session interruption and service shutdown leave no orphan process.
- Invalid or expired PTY IDs return bounded errors rather than crashing the host.
- Existing V1 tests and package entry point remain unchanged.
Would V2 support be in scope once the API settles? I can help test a branch against current opencode2 previews.
would love to see this. especially the options for plugins. and being able to fix the port there - allowing me to add plugin and specific port in main opencode.json to be set for all projects.
I have implemented OpenCode V2 plugin support in #59!
Highlights:
- Decoupled Adapter Layer: Core PTY management and permissions dispatching are now host-agnostic via clean interfaces (
SessionNotifier,PermissionAuthorizer,HostAdapter). - Dedicated V2 Entrypoint: Added
opencode-pty/v2export conforming toPlugin.define({ id: "opencode-pty", setup })while preserving 100% backwards compatibility for V1. - Configurable Port & Options: Supported plugin options via
ctx.options(addressing @BananaAcid's request). You can now configure a fixed port and hostname inopencode.json:{ "plugins": [ { "package": "opencode-pty/v2", "options": { "port": 4200, "hostname": "127.0.0.1" } } ] } - Command Transforms & Cleanup: Slash commands (
/pty-open-background-spy,/pty-show-server-url) are registered viactx.command.transform, and session cleanup is hooked up to prevent orphan processes. - Live Verification: Tested and validated live against the
opencode2CLI and external plugin loader specifications.