Skip to content

Add opencode as a connectable MCP agent and a chat harness - #80

Open
askmaddyy wants to merge 4 commits into
diffusionstudio:mainfrom
askmaddyy:feat/opencode-integration
Open

askmaddyy wants to merge 4 commits into
diffusionstudio:mainfrom
askmaddyy:feat/opencode-integration

Conversation

@askmaddyy

Copy link
Copy Markdown

Adds opencode to the two places Diffusion Studio connects to an agent.

MCP settings -> Agents

A new opencode row writes the app's diffusion entry into ~/.config/opencode/opencode.json, under opencode's own mcp root:

{ "mcp": { "diffusion": { "type": "remote", "url": "http://127.0.0.1:3274/mcp" } } }

This needs a new ConfigFormat ("mcp"); the JSON merge / remove / read paths are shared with the existing JSON agents, so only the root key and the entry shape differ. enabled is omitted because opencode defaults it to true.

Chat agent picker

OpenCodeHarness spawns opencode serve on a loopback port it picks, creates (or resumes) a session, streams the turn from the server's SSE /event feed, and maps text, reasoning, tool calls, and permission.asked / question.asked onto the existing Item and QuestionBox types. Interrupt, close and resume follow the codex adapter.

One child server per live session, so its event stream carries only that project's work. The MCP entry and the chat instructions are injected as OPENCODE_CONFIG_CONTENT and a per-prompt system, so nothing is written to the user's own config.

Picker

  • Models are grouped by model.group into a submenu per provider, labelled with the provider's display name.
  • probe reads GET /provider from a short-lived opencode serve (~400ms), so each model carries its real display name (Claude Sonnet 4.6, not claude-sonnet-4-6) and its provider's name as the group (OpenCode Zen). Only connected providers are listed.
  • The submenu caps at max-h-96, so a provider's seventy-odd models scroll instead of filling the screen.
  • The harness icon is the official opencode mark.

HarnessInfo.models gained an optional group; models without one list flat, so Claude Code and Codex are unchanged.

Testing

  • npm run check - agent-chat, desktop, web all pass
  • npm test - agent-chat 42 pass; desktop 58 pass (the 3 projects.watch.test.ts failures are a pre-existing flake, reproduced on a clean checkout)
  • npm run lint - clean
  • End to end: the generated opencode.json is read by opencode itself (opencode mcp list reports diffusion connected), and a live turn against opencode 1.18.31 streams item.started -> item.delta -> item.completed and resolves completed, with the diffusion MCP injected inline

Pre-existing and unrelated: packages/encoder (and its dependents) fail typecheck on showSaveFilePicker in packages/assets/src/browser.ts.

The Agents settings can now write the app's MCP entry into ~/.config/opencode/opencode.json under its `mcp` root (type: "remote"), and the chat picker offers opencode's models through a host that drives `opencode serve` over HTTP and Server-Sent Events, one child server per session.
The probe reads GET /provider from a short-lived `opencode serve`, so each model carries its display name and its provider's name as a group. The picker collapses models into a submenu per group instead of one flat list, so a harness with a hundred models is a few rows.
The base submenu caps at the viewport height, which lets a provider's seventy-odd models fill the screen. A fixed cap keeps the menu and its scrollbar a readable size; other submenus are untouched.
@vercel

vercel Bot commented Sep 19, 2026

Copy link
Copy Markdown

@askmaddyy is attempting to deploy a commit to the Diffusion Studio Team on Vercel.

A member of the Team first needs to authorize 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.

1 participant