feat(opencode): add opencode integration — /mcpctl switcher + footer indicator
Some checks failed
CI/CD / typecheck (pull_request) Successful in 1m16s
CI/CD / test (pull_request) Successful in 1m25s
CI/CD / lint (pull_request) Successful in 2m42s
CI/CD / smoke (pull_request) Failing after 1m59s
CI/CD / build (pull_request) Successful in 4m54s
CI/CD / publish (pull_request) Has been skipped

Implements mcpctl as an opencode addon, mirroring the prime-agent UX
(active-project indicator + a /mcpctl project switcher). opencode is a
native MCP client, so instead of a bridge this mounts the active project's
proxy MCP gateway through opencode's own live MCP API.

- src/opencode-ext/mcpctl-opencode.ts — server plugin (headless runs): mounts
  the active project under a stable `mcpctl` name via `client.mcp.add`,
  re-asserting on first contact and before each turn; never throws.
- src/opencode-ext/mcpctl-opencode-tui.tsx — TUI plugin: `/mcpctl`,
  `/mcpctl-status`, `/mcpctl-skills`, and a `mcpctl:<project>` indicator in
  the prompt footer (next to the model name, above the token counter); the
  switch delegates to the CLI then re-points the mount live.
- `mcpctl config opencode` — provision/reuse the project mcptoken, install +
  register the plugins (tui.json), write the 0600 state file, sync skills.
- `skills sync --agent opencode` — new shared-tree target
  (~/.config/opencode/skill).
- embedded-source generator + embed test, settings/config/order tests,
  completions, README + docs/opencode-extension.md.

Typechecked against the real @opencode-ai/plugin types (1.18.15).
This commit is contained in:
Michal
2026-08-08 22:45:38 +01:00
parent 2513da33c3
commit 9448c117df
20 changed files with 2500 additions and 28 deletions

View File

@@ -195,6 +195,51 @@ Inside pi:
See [docs/pi-extension.md](docs/pi-extension.md) for full details.
### Connect opencode
[opencode](https://opencode.ai) is a native MCP client, so mcpctl ships an
opencode integration that mounts the active project's proxy MCP gateway as an
MCP server — no extra MCP library, and no `~/.claude` dependency.
```bash
mcpctl config opencode --project monitoring
```
This installs two plugins into `~/.config/opencode/`:
- **server plugin** (`plugin/mcpctl.ts`) — auto-discovered; mounts the active
project's MCP gateway through opencode's own live MCP API, so headless runs
(`opencode run ...`) see the project's tools too;
- **TUI plugin** (`mcpctl/mcpctl-tui.tsx`, registered in `tui.json`) — the
`/mcpctl` switcher and a `mcpctl:<project>` indicator in the prompt footer.
It also mints/reuses the project's bearer token (stored 0600 in
`~/.mcpctl/opencode-state.json`), and runs an initial skills sync into
`~/.config/opencode/skill/`.
Inside opencode:
- `/mcpctl`**switch project** from a filterable picker
- `/mcpctl-status` — show the active project + MCP mount state
- `/mcpctl-skills` — re-sync this project's skills into opencode's skill dir
- the active project shows up as `mcpctl:<project>` next to the model name,
just above the token counter — switch it without restarting opencode
Options (mirror the prime-agent command):
```bash
mcpctl config opencode --project monitoring --token mcpctl_pat_xxx # provide token, don't mint
mcpctl config opencode --project monitoring --skip-skills # don't sync skills
mcpctl config opencode --project monitoring --skip-plugin # don't (re)install the plugins
mcpctl config opencode --project monitoring --skip-marker # don't touch .mcpctl-project here
mcpctl config opencode --project monitoring --opencode-dir /path # custom opencode config dir
mcpctl config opencode --project monitoring --dry-run # preview only
```
The `/mcpctl` switcher runs with `--skip-plugin --skip-marker`, so switching
projects from inside opencode never re-scopes whichever repository opencode
happened to be started in.
## Declarative Configuration
Everything can be defined in YAML and applied with `mcpctl apply`: