mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
- Add @opencode-manager/workspace-plugin package - Add API tokens management with scoped access control - Add workspace-plugin routes for project discovery - Add bearer token authentication for external access - Add proxy WebSocket support for remote workspaces - Add frontend UI for API token management - Update documentation with workspace plugin guide
4.7 KiB
4.7 KiB
Workspace Plugin
The workspace plugin allows you to connect your local OpenCode TUI to a running opencode-manager instance and use its projects as remote workspaces.
Overview
The workspace plugin consists of two main components:
- Manager-side: Backend endpoints and authentication for serving project information
- Plugin: An OpenCode plugin that connects to the manager and registers remote workspaces
Features
- Bearer Token Authentication: Secure API tokens for external access
- Project Discovery: Automatically discover and register all manager projects
- Remote Workspace Support: Use manager projects as remote workspaces in OpenCode TUI
- SSE Streaming: Server-sent events are properly streamed (not buffered)
- WebSocket Support: WebSocket connections are proxied correctly
Setup
1. Create an API Token
- Open your opencode-manager web UI
- Navigate to Settings → API Tokens
- Click "Create Token"
- Give it a descriptive name (e.g., "OpenCode TUI")
- Copy the token immediately - it won't be shown again
- Store the token securely
2. Install the Plugin
In your OpenCode configuration (opencode.json), add:
{
"plugin": [
["@opencode-manager/workspace-plugin", {
"url": "http://localhost:5003",
"token": "<your-bearer-token>"
}]
]
}
Or use environment variables:
export OPENCODE_MANAGER_URL="http://localhost:5003"
export OPENCODE_MANAGER_TOKEN="<your-bearer-token>"
3. Start OpenCode TUI
Launch the OpenCode TUI. You should see your manager projects appear in the workspace picker as manager:<slug>.
How It Works
- Plugin Initialization: When OpenCode starts, the plugin calls
GET /api/workspace-plugin/projectson the manager - Project Registration: For each project returned, the plugin registers a
WorkspaceAdaptorwith typemanager:<slug> - Workspace Selection: When you select a workspace in the TUI, the adaptor provides:
- Remote target URL:
<manager>/api/opencode - Authorization header:
Bearer <token> - Project slug header:
x-opencode-manager-project: <slug>
- Remote target URL:
- Request Proxying: The manager proxies requests to the embedded OpenCode server with the appropriate
?directory=parameter
API Reference
GET /api/workspace-plugin/projects
Returns a list of projects available in the manager.
Authentication: Bearer token or session cookie
Response:
{
"projects": [
{
"slug": "1",
"name": "my-project",
"directory": "/path/to/project",
"description": "https://github.com/user/repo.git"
}
]
}
GET /api/settings/tokens
List all API tokens for the current user.
Response:
{
"tokens": [
{
"id": "uuid",
"name": "token-name",
"scope": "workspace-plugin",
"lastUsedAt": 1234567890,
"createdAt": 1234567890,
"expiresAt": null
}
]
}
POST /api/settings/tokens
Create a new API token.
Request:
{
"name": "token-name",
"scope": "workspace-plugin",
"expiresAt": 1234567890
}
Response:
{
"id": "uuid",
"name": "token-name",
"token": "raw-token-shown-once"
}
DELETE /api/settings/tokens/:id
Revoke an API token.
Security Considerations
- Token Storage: Tokens are stored as SHA-256 hashes in the database
- One-Time Display: Raw tokens are shown only once on creation
- Token Revocation: Tokens can be revoked at any time from the Settings UI
- Scope Restriction: Tokens have a
workspace-pluginscope by default - CORS Bypass: Bearer tokens bypass CORS origin requirements (explicit opt-in)
Token Scopes
workspace-plugin: Access to workspace plugin endpoints (default)*: Full access to all protected endpoints
Troubleshooting
Plugin fails to connect
- Verify the manager URL is correct and accessible
- Check that the token is valid and not expired
- Ensure the token has the correct scope (
workspace-plugin) - Check the manager logs for authentication errors
Projects don't appear
- Verify the manager has projects configured
- Check that the token has not been revoked
- Look for errors in the OpenCode TUI console
SSE events not streaming
The proxy has been updated to stream response bodies instead of buffering. If you experience issues:
- Check that the manager is running the latest version
- Verify the upstream OpenCode server is sending proper SSE headers
- Look for buffering in network inspection tools
Development
Testing the Plugin
cd packages/workspace-plugin
pnpm test
pnpm typecheck
Testing the Manager
cd backend
pnpm test test/services/api-tokens.test.ts
pnpm test test/routes/workspace-plugin.test.ts