# opencode-link **Repository Path**: oyster_qi/opencode-link ## Basic Information - **Project Name**: opencode-link - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-27 - **Last Updated**: 2026-02-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OpenCode-Link Multi-host OpenCode window collaboration system for LAN environments. ## Architecture ``` ┌─────────────────────────────────────────────────────────────────────┐ │ 局域网 │ │ ┌───────────────────────────┐ ┌───────────────────────────┐ │ │ │ 主机 A │ │ 主机 B │ │ │ │ ┌───────────────────┐ │ │ ┌───────────────────┐ │ │ │ │ │ Gateway A │◄───┼───────┼─►│ Gateway B │ │ │ │ │ │ :4096 (HTTP/WS) │ │ mDNS │ │ :4096 (HTTP/WS) │ │ │ │ │ └─────────┬─────────┘ │ 自动发现│ └─────────┬─────────┘ │ │ │ │ │ │ │ │ │ │ │ │ ┌─────┴─────┐ │ │ ┌─────┴─────┐ │ │ │ │ ▼ ▼ ▼ │ │ ▼ ▼ │ │ │ │ ┌────┐ ┌────┐ ┌────┐ │ │ ┌────┐ ┌────┐ │ │ │ │ │:db │ │:api│ │:tst│ │ │ │:fe │ │:dep│ │ │ │ │ │Plug│ │Plug│ │Plug│ │ │ │Plug│ │Plug│ │ │ │ │ └────┘ └────┘ └────┘ │ │ └────┘ └────┘ │ │ │ └───────────────────────────┘ └───────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────┘ ``` ## Features - 🏷️ **Tag-based routing**: Send messages to OpenCode windows by tag (e.g., `:db`, `:frontend`) - 🔍 **Auto-discovery**: mDNS automatic discovery of other hosts on LAN - 💬 **Request-Response**: Synchronous message exchange between windows - 🔌 **Plugin-based**: Integrates with OpenCode as a plugin - 🌐 **Decentralized**: Each host runs a Gateway, no central server required ## Installation ### Prerequisites - Node.js 18+ or Bun - pnpm 8+ ### Setup ```bash # Install dependencies pnpm install # Build all packages pnpm build ``` ## Usage ### 1. Start Gateway On each host machine: ```bash # Start the gateway server (port 4096 by default) pnpm dev:gateway ``` Or with custom port: ```bash OPENCODE_LINK_PORT=5000 pnpm dev:gateway ``` ### 2. Install Plugin in OpenCode Add the plugin to your OpenCode configuration: ```json // opencode.json { "plugin": ["@opencode-link/plugin"] } ``` Or install locally: ```bash cd KuaiYingYongWeb pnpm add @opencode-link/plugin ``` ### 3. Use in OpenCode Once the plugin is loaded and Gateway is running, OpenCode will: 1. Automatically register with the local Gateway 2. Receive a tag (auto-generated or manual) 3. Get access to the `send_to_tag` tool **Example usage:** ``` User: "Send a message to the frontend tag asking about API response format" AI: [Uses send_to_tag tool] tag: "frontend" message: "What's the expected API response format?" ``` ## API Reference ### Gateway HTTP API #### `POST /register` Register an OpenCode window with the Gateway. ```json // Request { "sessionId": "session_123", "tag": "optional-custom-tag" } // Response { "tag": "window-1234567890", "gatewayId": "abc123xyz", "sessionId": "session_123" } ``` #### `GET /peers` Get all available tags on the network. ```json // Response { "peers": [ { "tag": "db", "host": "localhost:4096", "local": true }, { "tag": "frontend", "host": "192.168.1.100:4096", "local": false } ] } ``` #### `POST /send` Send a message to another OpenCode window. ```json // Request { "toTag": "frontend", "fromTag": "db", "content": "What's the API schema?", "timeout": 30000 } // Response { "success": true, "response": "Message delivered" } ``` ## Development ```bash # Run both gateway and plugin in dev mode pnpm dev # Run tests pnpm test # Build all packages pnpm build ``` ## Project Structure ``` opencode-link/ ├── package.json # Root package (workspace) ├── pnpm-workspace.yaml # Workspace config ├── packages/ │ ├── gateway/ # Gateway server component │ │ ├── src/ │ │ │ └── index.ts # Main gateway logic │ │ └── package.json │ └── plugin/ # OpenCode plugin component │ ├── src/ │ │ └── index.ts # Plugin implementation │ └── package.json ``` ## Protocol ### Message Flow 1. **Local Message** ``` User → Plugin → Gateway (HTTP) → WebSocket → Target Plugin → OpenCode ``` 2. **Remote Message** ``` User → Plugin → Gateway A → Gateway B → Target Plugin → OpenCode Response → Gateway B → Gateway A → Original Plugin → User ``` ### mDNS Service Discovery - Service type: `opencode-link` - TXT record contains: `{ id, version, port }` ## Troubleshooting ### Gateway not discovering other hosts 1. Check firewall settings (port 4096 or custom) 2. Verify mDNS is allowed on your network 3. Check that both gateways are on the same subnet ### Plugin not connecting to Gateway 1. Ensure Gateway is running before starting OpenCode 2. Check Gateway logs for registration messages 3. Verify port configuration matches ## License MIT