Skip to content

feat: support OpenCode 2 through a ./tui CLI plugin entrypoint - #28

Open
NimbleAINinja wants to merge 1 commit into
warpdotdev:mainfrom
NimbleAINinja:opencode-v2-support
Open

NimbleAINinja wants to merge 1 commit into
warpdotdev:mainfrom
NimbleAINinja:opencode-v2-support

Conversation

@NimbleAINinja

Copy link
Copy Markdown

What

OpenCode 2 can't load the plugin (#27): it requires a default export with an id and setup(), so 0.1.7 fails with Plugin must export a default definition with an id and an effect or setup function.

Changing the export isn't enough on its own. OpenCode 2 runs opencode.json plugins inside a shared background service (opencode serve --service) that has no controlling terminal, so a server plugin can't write the OSC 777 sequence to the Warp pane.

How

  • New ./tui export (src/tui.ts, logic in src/v2.ts). OpenCode 2 loads it as a CLI plugin from cli.json, in the opencode process attached to the Warp pane, so warpNotify works unchanged.

  • Same Warp payloads as today. OpenCode 2 events are mapped onto the existing protocol:

    OpenCode 2 event Warp event
    session.execution.started prompt_submit (last user message)
    session.execution.succeeded / interrupted / failed, session.idle stop (once per turn, with query/response)
    permission.asked permission_request
    permission.replied (not reject) permission_replied
    session.tool.success / failed tool_complete (tool name from session.tool.input.started)
    form.created question_asked (OpenCode 2 asks questions through forms, not the question tool)
  • Only this client's sessions. The event bus is shared by every client attached to the service, so events are checked against the session the client is showing, or one of its open tabs. Otherwise every Warp pane running opencode would get every other pane's notifications.

  • Subagent sessions are skipped, as in fix: suppress stop notifications for subagent sessions #22.

  • session_start handshake at launch. It goes out about 1s after startup, for the session on screen or the most recent root session in the working directory. Otherwise Warp's "Install Warp Plugin for OpenCode" chip stays up until the first prompt. This is the same problem fix: re-emit session_start after plugin init to fix missed handshake race #25 fixes for v1.

  • OpenCode 1 is unchanged. The main entry still exports only WarpPlugin. The version and title constants moved to src/constants.ts so both entries share them; they are still not re-exported from index.ts.

  • No new dependencies. The small subset of the OpenCode 2 CLI plugin context that's used is typed locally, so the lockfile is untouched.

Trade-offs

  • Install is manual for OpenCode 2. Users add the package to cli.json by hand; the README now says so. opencode plugin add registers any package with a server entry in opencode.json, and since the main entry is the v1 plugin, it would land where it fails to load. Making the main entry a dual v1/v2 object would fix that. But OpenCode only accepts object entrypoints from 1.18.29, so it would break older v1 installs. That seemed like a call for you, so I left it out.

Testing

  • bun run typecheck clean, bun test: 38 pass (12 new in tests/v2.test.ts covering the event mapping, per-turn stop dedupe, subagent and other-client filtering, background tabs, and the launch handshake).
  • Packaging: packed with npm pack and installed into a scratch project. @warp-dot-dev/opencode-warp/tui resolves to dist/tui.js, the package root still resolves to the v1 entry, and it exports only WarpPlugin.
  • End to end: OpenCode 2.0.14 on Linux (Omarchy, Warp v0.2026.09.16.08.27.stable_02). Loaded the packaged ./tui from cli.json. Notifications for prompt, permission, question, and completion appear in Warp, and the setup chip clears at launch. The same logic also runs on OpenCode 2.0.11.
  • Not tested: Windows, and macOS under OpenCode 2.

Fixes #27

🤖 Generated with Claude Code

https://claude.ai/code/session_01X3DNN9JJut23XgnZFwhXgm

OpenCode 2 can't load the plugin (warpdotdev#27): it requires a default export with
an id and setup(), and its server plugins run in a shared background
service with no terminal, so they couldn't reach Warp anyway.

Add a ./tui export that OpenCode 2 loads as a CLI plugin (cli.json) in the
opencode process attached to the Warp pane. It maps OpenCode 2 events to
the existing Warp payloads, only notifies for sessions the client is
showing (the event bus is shared by every attached client), skips
subagent sessions, and sends the session_start handshake at launch so
Warp's setup chip clears before the first prompt.

The main entry is unchanged, so OpenCode 1 keeps working.

Fixes warpdotdev#27

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X3DNN9JJut23XgnZFwhXgm
@ragokan

ragokan commented Sep 26, 2026

Copy link
Copy Markdown

Follow-up to #28, from a branch based on ae2f893 (not a replacement — pull ragokan:v2-server-entry if you prefer to fold it into this PR).

What

./tui makes the notifications work on OpenCode 2, but it leaves the server entry unloadable. src/index.ts has no default export, so OpenCode 2 rejects the module with a different error than the one in the description:

failed to load plugin target=@warp-dot-dev/opencode-warp
  cause="PluginModule.LoadError: Plugin must export a default definition with an id
  and an effect or setup function. (cause: SchemaError(Missing key at ["default"])))"

opencode plugin add registers a server entry, so the published plugin still errors on every startup — which is why the trade-off note here said install is manual and told users not to run that command. The v1 plugin and v2 CLI entry are both fine; the gap is the main entry.

This adds one default export carrying both halves:

export default {
    id: "warp",
    setup() {},
    server: WarpPlugin,
}

setup is inert on purpose. Server plugins run in a shared background service with no controlling terminal, so they cannot write the OSC 777 sequences — ./tui still does that, in the process attached to the Warp pane. The entry exists so the opencode.json install stops erroring; the README now says that instead of telling users to avoid opencode plugin add. Keeping both entries configured is harmless.

On the trade-off called out here

Making the main entry a dual v1/v2 object would fix that. But OpenCode only accepts object entrypoints from 1.18.29, so it would break older v1 installs.

Agreed on the mechanism, and it is the only one available: the host version can't be selected at resolve time, since exports conditions are chosen by the importing runtime, not by the OpenCode version. So the cost is bounded to v1 installs older than 1.18.29, which stop loading the plugin from the main entry. WarpPlugin is untouched and still exported, so anyone on such a release can keep an entry pointing at it. Happy to drop this if you'd rather keep the main entry function-only and just document the plugin add caveat.

Testing

  • bun run typecheck clean; bun test 41 pass, 3 new in tests/entry.test.ts (default export is an object with id/setup, server is the v1 plugin, setup stays inert).
  • npm pack, installed the tarball into a scratch project, and confirmed dist/index.js default-exports { id: "warp", setup, server } with server === WarpPlugin.
  • End to end on OpenCode 2.0.18 / macOS (the untested platform in the description): swapped the packed dist/ into the installed package, restarted the service, and /api/plugin goes from failed: Missing key at ["default"] to {"id":"warp","status":"active"}. Both this plugin and @dietrichgebert/ponytail now report active in the same query, so the two v2 load failures clear together.
  • Not verified: that notifications actually appear in a Warp pane from the ./tui entry on macOS — that path is feat: support OpenCode 2 through a ./tui CLI plugin entrypoint #28's and its Linux result should carry over, but I did not drive a session through it.

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.

OpenCode V2 plugin load fails: missing default export in @warp-dot-dev/opencode-warp 0.1.7

2 participants