Skip to content

feat: add OpenCode V2 plugin API support and adapter architecture (#55) - #59

Merged
shekohex merged 1 commit into
shekohex:mainfrom
kumar-shivang:feat/opencode-v2-support
Sep 18, 2026
Merged

shekohex merged 1 commit into
shekohex:mainfrom
kumar-shivang:feat/opencode-v2-support

Conversation

@kumar-shivang

Copy link
Copy Markdown
Contributor

Resolves #55

Context & Motivation

OpenCode V2 redesigns the plugin interface around Plugin.define({ id, setup }), native options in ctx.options, and stateful domain transform hooks (ctx.command.transform, etc.). This PR introduces OpenCode V2 support to opencode-pty while 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

  1. Host Adapter Layer (src/adapters/):

    • Introduced host-agnostic interfaces:
      • SessionNotifier: Decouples exit notification dispatching from @opencode-ai/sdk (OpencodeClient).
      • PermissionAuthorizer: Decouples command and workdir permission checks from V1 PluginClient.
      • HostAdapter: Unified interface bundling notifier, authorizer, and session deletion callbacks.
    • Built V1PermissionAuthorizer and V1NotificationAdapter in src/adapters/v1/ to power the V1 entry point.
    • Decoupled PTYManager and permissions.ts so they delegate to active adapters while retaining full backward compatibility.
  2. OpenCode V2 Plugin Entrypoint (src/v2/index.ts):

    • Implemented V2 plugin definition conforming to Plugin.define({ id: "opencode-pty", setup: async (ctx) => ... }).
    • Added ./v2 export in package.json for seamless loading via "plugin": ["opencode-pty/v2"] or "plugins": [...].
    • Re-exports standard PTY tools (pty_spawn, pty_write, pty_read, pty_list, pty_kill).
  3. Plugin Options & Configurable Port Support:

    • Added OpencodePtyOptions (port, hostname, autostart) accessible through ctx.options.
    • Updated PTYServer.createServer(options?: ServerOptions) to support custom port and hostname binding (addressing community feedback from Plan OpenCode V2 plugin API support #55).
  4. V2 Commands & Lifecycle:

    • In V2, commands (/pty-open-background-spy, /pty-show-server-url) are registered via ctx.command.transform.
    • Built V2HostAdapter to automatically invoke manager.cleanupBySession(id) on session deletion.
  5. Testing & Quality:

    • Added test/adapters.test.ts: Validates SessionNotifier and PermissionAuthorizer decoupling.
    • Added test/v2.test.ts: Validates V2 contract conformance, command registration, and options handling.
    • Added test/opencode-v2-live.test.ts: Live integration testing against OpenCode V2 external plugin loader specs.
    • All 82 tests pass across 16 test suites.
    • 0 TypeScript errors, 0 Biome lint errors/warnings.

…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
@shekohex

Copy link
Copy Markdown
Owner

Thank you! I will release a new version soon.

@shekohex
shekohex merged commit 3e28929 into shekohex:main Sep 18, 2026
7 checks passed
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.

Plan OpenCode V2 plugin API support

2 participants