Skip to content

feat!: support native OpenCode v2 - #3

Draft
krmcbride wants to merge 6 commits into
masterfrom
feat/opencode-v2
Draft

krmcbride wants to merge 6 commits into
masterfrom
feat/opencode-v2

Conversation

@krmcbride

@krmcbride krmcbride commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Summary

Port the plugin to native OpenCode v2 while preserving the external-server workflow: Neovim opens a TUI in Snacks and connects to a separately managed server, which can run inside a third-party sandbox. The v2 CLI, plugin SDK, HTTP API, and event envelopes replace the v1 contracts.

Changes

  • Launch with an explicit --server, positional directory, and new/continue/explicit-session behavior. Load the native TUI bridge directly from a plugin checkout without installing development dependencies.
  • Track the visible session's native directory/workspace and forward owned lifecycle, permission, and form events. Discard stale callbacks and queued events across reconnects and route changes.
  • Send reviews through native prompt admission using ranged file URIs and the session's current agent/model. Clear only acknowledged, unchanged queued comments; retain uncertain sends for manual inspection.
  • Parse fragmented SSE frames and comment heartbeats, reconnect with a fresh session snapshot, and check project buffers after execution or reconnect. Honor inherited and explicit autoread settings while preserving dirty buffers.

Compatibility and migration

This is a breaking, v2-only migration. V1 users should pin aa2a146. Register the repository's absolute path in writable v2 cli.json, and provide the backend password in Neovim's environment.

The migration guide covers client registration, authentication, custom event hooks, and an upgrade checklist. Update bridge registration and any custom event hooks when upgrading. Server installation and service management remain external to the plugin.

Validation

  • nix develop --command bun run typecheck — passed against the published v2 SDK.
  • nix develop --command bun run test — 8 Bun tests and 15 headless Lua tests passed. The Lua suite also passed with Neovim 0.12.4, alongside the dev shell's 0.11.5.
  • nix develop --command stylua --check lua plugin tests and diff whitespace checks — passed.
  • Live OpenCode 2.0.1 with Fence sandbox, Neovim 0.12.4, and real Snacks: new/continue/explicit-session launch, split/tab layouts, native ranged mentions, prompt submission, direct and batched reviews, an idle interval beyond the heartbeat, clean-buffer reload, dirty-buffer preservation, and reconnect after a confirmed missed disk edit all passed. Persisted messages retained the selected ranges and session agent/model/variant. A clean bridge copy without node_modules loaded successfully.
  • Closing the test TUIs left the server's process unchanged with zero restarts. Disposable test sessions were deleted.

Permission/form interactive UI flows and remote workspace runtimes have fixture/source coverage only. Runtime testing used 2.0.1; the relevant contracts were also checked against upstream v2 source at 195158c3.

The commits separate the TUI port, backend/review port, regression fixes, and migration documentation for review.

Guard retry callbacks across unsubscribe and resubscribe, and recheck the TUI route while draining queued events. Add regressions for both scheduler races identified during review.
Keep the native Plugin.Definition contract as a type-only import so a plugin-manager checkout can load directly in OpenCode. Verify the entrypoint in a clean temporary directory with package installation disabled.
Resolve an unset buffer-local autoread option through its global value while preserving explicit buffer overrides. Cover both inheritance directions and verify settlement and reconnect reloads inside the native TUI.
Document external server connections, writable CLI bridge registration,
native event hooks, and review delivery. Include migration steps and
validation coverage for the v2 port.
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