Skip to content

Dual-protocol client: OpenCode V1 and V2 wire APIs - #494

Draft
jensenojs wants to merge 1 commit into
sudo-tee:mainfrom
jensenojs:wip-v2
Draft

jensenojs wants to merge 1 commit into
sudo-tee:mainfrom
jensenojs:wip-v2

Conversation

@jensenojs

Copy link
Copy Markdown
Collaborator

Summary

Reworks the client to speak both OpenCode wire protocols (V1 1.18.x and V2 2.0.x) through a single connection/observation architecture.

What changed

  • New protocols/{v1,v2} modules own native endpoints and event interpretation per protocol; ui/ consumes one read-only per-session Observation instead of reducing protocol events.
  • Connection selection: authenticated health probe picks the protocol once per connection; reconnect on identity change, no per-request branching.
  • V2 uses the native shared service via CLI discovery (service status / get password); V1 keeps local spawn, explicit URLs, and port coordination.
  • Removed api_client, event_manager, session, renderer/events, event_scope, session_scope.
  • Topbar cost/context stats now derive from observation usage (V2 session.usage.updated / snapshot first, latest entry fallback for V1).
  • run_tests.sh now names the spec file when a test file dies at load time (e.g. requiring a removed module), instead of a bare non-zero exit.

Contract

The published OpenAPI spec and the running 2.0.x server disagree at several endpoints (/api/project/current, rename via POST, prompt command field, fork body shape). This implementation follows the running server; fixtures under tests/data/v2/ are live captures from a real 2.0.1 server. Known future break: upstream dev renames permission.asked / form.* events.

Details in docs/drafts/v2-migration-draft.md (temporary draft intended to be folded into docs later).

Testing

  • ./run_tests.sh green (minimal, unit, replay).
  • Per-protocol contract suites: protocol_{v1,v2}_{operations,observation}*_spec.lua.
  • Live dual-client check done against a real 2.0.3 shared service (native discovery, auth, event stream, prompt admission, both TUI↔nvim visibility).

@jensenojs
jensenojs force-pushed the wip-v2 branch 2 times, most recently from cc67b2d to 88f78f1 Compare September 15, 2026 19:02
* refactor: replace api_client/event_manager/session with per-protocol
  operations and Observation modules under protocols/{v1,v2}

* feat: auth health probe selects the protocol once per connection;
  identity change forces reconnect, no per-request branching

* feat: connect to the native V2 shared service via CLI discovery;
  V1 keeps local spawn, explicit URLs, and port coordination

* fix(renderer): rebuild topbar stats bridge from observation usage
  (session.usage.updated and snapshot first, latest entry fallback)

* fix(v2): handle session.usage.updated; drop dead branches for
  server-absent session.tool.error and file.watcher.updated

* test: per-protocol contract suites and live-captured V2 fixtures
  from a real 2.0.1 server; counterexamples for cross-session event
  pollution and malformed usage payloads

* docs: add migration draft under docs/drafts; update bidirectional-sync
  recipe for the native V2 service path
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