feat: add OpenCode V2 plugin API support and adapter architecture (#55) - #59
Merged
Merged
Conversation
…ekohex#55) - Decouple core PTY manager and permissions dispatcher from V1 PluginClient via host-agnostic adapter interfaces (SessionNotifier, PermissionAuthorizer, HostAdapter) - Add dedicated OpenCode V2 entrypoint at opencode-pty/v2 with Plugin.define({ id, setup }) contract - Implement configurable options via ctx.options (custom port, hostname, autostart) - Support custom port and hostname in PTYServer.createServer - Map commands to V2 ctx.command.transform and export PTY tools for V2 - Preserve 100% backwards compatibility with OpenCode V1 plugin interface - Add unit and live integration tests for V2 runtime conformance
Owner
|
Thank you! I will release a new version soon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #55
Context & Motivation
OpenCode V2 redesigns the plugin interface around
Plugin.define({ id, setup }), native options inctx.options, and stateful domain transform hooks (ctx.command.transform, etc.). This PR introduces OpenCode V2 support toopencode-ptywhile preserving 100% backwards compatibility with OpenCode V1 plugins and entry points. It also addresses the request to configure custom server ports via plugin options.Summary of Changes
Host Adapter Layer (
src/adapters/):SessionNotifier: Decouples exit notification dispatching from@opencode-ai/sdk(OpencodeClient).PermissionAuthorizer: Decouples command and workdir permission checks from V1PluginClient.HostAdapter: Unified interface bundling notifier, authorizer, and session deletion callbacks.V1PermissionAuthorizerandV1NotificationAdapterinsrc/adapters/v1/to power the V1 entry point.PTYManagerandpermissions.tsso they delegate to active adapters while retaining full backward compatibility.OpenCode V2 Plugin Entrypoint (
src/v2/index.ts):Plugin.define({ id: "opencode-pty", setup: async (ctx) => ... })../v2export inpackage.jsonfor seamless loading via"plugin": ["opencode-pty/v2"]or"plugins": [...].pty_spawn,pty_write,pty_read,pty_list,pty_kill).Plugin Options & Configurable Port Support:
OpencodePtyOptions(port,hostname,autostart) accessible throughctx.options.PTYServer.createServer(options?: ServerOptions)to support custom port and hostname binding (addressing community feedback from Plan OpenCode V2 plugin API support #55).V2 Commands & Lifecycle:
/pty-open-background-spy,/pty-show-server-url) are registered viactx.command.transform.V2HostAdapterto automatically invokemanager.cleanupBySession(id)on session deletion.Testing & Quality:
test/adapters.test.ts: ValidatesSessionNotifierandPermissionAuthorizerdecoupling.test/v2.test.ts: Validates V2 contract conformance, command registration, and options handling.test/opencode-v2-live.test.ts: Live integration testing against OpenCode V2 external plugin loader specs.