@willjackson/claude-code-bridge 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +690 -0
- package/dist/chunk-BRH476VK.js +1993 -0
- package/dist/chunk-BRH476VK.js.map +1 -0
- package/dist/cli.d.ts +40 -0
- package/dist/cli.js +844 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +1848 -0
- package/dist/index.js +976 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Will Jackson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,690 @@
|
|
|
1
|
+
# Claude Code Bridge
|
|
2
|
+
|
|
3
|
+
A bidirectional communication system that enables two separate Claude Code instances to collaborate across different environments.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Overview](#overview)
|
|
8
|
+
- [Features](#features)
|
|
9
|
+
- [Installation](#installation)
|
|
10
|
+
- [Quick Start](#quick-start)
|
|
11
|
+
- [CLI Reference](#cli-reference)
|
|
12
|
+
- [Configuration](#configuration)
|
|
13
|
+
- [Environment Setup](#environment-setup)
|
|
14
|
+
- [Programmatic Usage](#programmatic-usage)
|
|
15
|
+
- [Troubleshooting](#troubleshooting)
|
|
16
|
+
- [Development](#development)
|
|
17
|
+
- [License](#license)
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
Claude Code Bridge connects a native macOS/Linux Claude Code instance with a Claude Code instance running inside a Docker-based development environment (Docksal, DDEV, Lando, or plain Docker).
|
|
22
|
+
|
|
23
|
+
### Architecture
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
┌─────────────────────────┐ ┌─────────────────────────┐
|
|
27
|
+
│ Local Mac │ │ Container (CLI/Web) │
|
|
28
|
+
│ ┌───────────────────┐ │ │ ┌───────────────────┐ │
|
|
29
|
+
│ │ Claude Code │ │ │ │ Claude Code │ │
|
|
30
|
+
│ │ (Desktop App) │ │ │ │ (Server App) │ │
|
|
31
|
+
│ └─────────┬─────────┘ │ │ └─────────┬─────────┘ │
|
|
32
|
+
│ │ │ │ │ │
|
|
33
|
+
│ ┌─────────┴─────────┐ │ WebSocket │ ┌─────────┴─────────┐ │
|
|
34
|
+
│ │ Bridge Plugin │◄─┼────────────────────┼─►│ Bridge Plugin │ │
|
|
35
|
+
│ │ (port 8766) │ │ │ │ (port 8765) │ │
|
|
36
|
+
│ └───────────────────┘ │ │ └───────────────────┘ │
|
|
37
|
+
└─────────────────────────┘ └─────────────────────────┘
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Use Cases
|
|
41
|
+
|
|
42
|
+
- **Cross-environment refactoring**: Coordinate changes between API client (desktop) and API server (container)
|
|
43
|
+
- **Context sharing**: Share code snippets, project structure, and summaries between instances
|
|
44
|
+
- **Task delegation**: Delegate tasks from one Claude Code instance to another
|
|
45
|
+
- **Multi-project coordination**: Work on related projects in different environments simultaneously
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- **WebSocket-based communication** with automatic reconnection
|
|
50
|
+
- **Environment auto-detection** for Docksal, DDEV, Lando, and Docker
|
|
51
|
+
- **Context synchronization** with configurable file patterns
|
|
52
|
+
- **Task delegation** with timeout handling
|
|
53
|
+
- **Peer-to-peer mode** allowing bidirectional communication
|
|
54
|
+
- **CLI and programmatic API** for flexible integration
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
### Prerequisites
|
|
59
|
+
|
|
60
|
+
- Node.js 20 or higher
|
|
61
|
+
- npm or pnpm
|
|
62
|
+
|
|
63
|
+
### Global Installation (Recommended)
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npm install -g claude-code-bridge
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Run Without Installing
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx claude-code-bridge start
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Install from Source
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
git clone https://github.com/willjackson/claude-code-bridge.git
|
|
79
|
+
cd claude-code-bridge
|
|
80
|
+
npm install
|
|
81
|
+
npm run build
|
|
82
|
+
npm link # Makes 'claude-bridge' available globally
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Quick Start
|
|
86
|
+
|
|
87
|
+
### Scenario 1: Mac to Docker Container
|
|
88
|
+
|
|
89
|
+
**Step 1: Start the bridge on your Mac**
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
claude-bridge start --port 8766
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Step 2: Start the bridge in your container and connect**
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Inside the container (Docksal, DDEV, or Docker)
|
|
99
|
+
claude-bridge start --port 8765 --connect ws://host.docker.internal:8766
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Scenario 2: Auto-Detection Mode
|
|
103
|
+
|
|
104
|
+
Let the bridge automatically detect your environment and configure itself:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# On Mac (auto-detects native environment, uses port 8766)
|
|
108
|
+
claude-bridge start --auto
|
|
109
|
+
|
|
110
|
+
# In container (auto-detects Docker environment, uses port 8765)
|
|
111
|
+
claude-bridge start --auto --connect ws://host.docker.internal:8766
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Scenario 3: Peer-to-Peer Mode
|
|
115
|
+
|
|
116
|
+
Both instances can initiate communication:
|
|
117
|
+
|
|
118
|
+
**Terminal 1 (Mac):**
|
|
119
|
+
```bash
|
|
120
|
+
claude-bridge start --port 8766
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Terminal 2 (Container):**
|
|
124
|
+
```bash
|
|
125
|
+
claude-bridge start --port 8765 --connect ws://host.docker.internal:8766
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Once connected, either side can send context or delegate tasks to the other.
|
|
129
|
+
|
|
130
|
+
## CLI Reference
|
|
131
|
+
|
|
132
|
+
### Global Options
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
Usage: claude-bridge [options] [command]
|
|
136
|
+
|
|
137
|
+
Options:
|
|
138
|
+
-V, --version Output the version number
|
|
139
|
+
-v, --verbose Enable verbose logging
|
|
140
|
+
--config <path> Path to config file
|
|
141
|
+
-h, --help Display help for command
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Commands
|
|
145
|
+
|
|
146
|
+
#### `start` - Start the Bridge Server
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
claude-bridge start [options]
|
|
150
|
+
|
|
151
|
+
Options:
|
|
152
|
+
-p, --port <port> Port to listen on (default: 8765 in container, 8766 native)
|
|
153
|
+
-h, --host <host> Host to bind to (default: 0.0.0.0)
|
|
154
|
+
-c, --connect <url> URL to connect to on startup (e.g., ws://localhost:8765)
|
|
155
|
+
-a, --auto Auto-detect environment and configure
|
|
156
|
+
-d, --daemon Run in background
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
**Examples:**
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Start with default settings
|
|
163
|
+
claude-bridge start
|
|
164
|
+
|
|
165
|
+
# Start on specific port
|
|
166
|
+
claude-bridge start --port 9000
|
|
167
|
+
|
|
168
|
+
# Start and connect to remote bridge
|
|
169
|
+
claude-bridge start --connect ws://192.168.1.100:8765
|
|
170
|
+
|
|
171
|
+
# Start in daemon mode
|
|
172
|
+
claude-bridge start --daemon
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
#### `stop` - Stop the Running Bridge
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
claude-bridge stop
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Stops the bridge daemon if running in background mode.
|
|
182
|
+
|
|
183
|
+
#### `status` - Show Bridge Status
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
claude-bridge status [options]
|
|
187
|
+
|
|
188
|
+
Options:
|
|
189
|
+
--port <port> Check status on specific port
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Shows:
|
|
193
|
+
- Bridge running state
|
|
194
|
+
- Listening port
|
|
195
|
+
- Connected peers
|
|
196
|
+
|
|
197
|
+
#### `connect` - Connect to Remote Bridge
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
claude-bridge connect <url>
|
|
201
|
+
|
|
202
|
+
Arguments:
|
|
203
|
+
url WebSocket URL (e.g., ws://localhost:8765)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Examples:**
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
claude-bridge connect ws://localhost:8765
|
|
210
|
+
claude-bridge connect ws://host.docker.internal:8766
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### `discover` - Discover Local Bridges
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
claude-bridge discover
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Searches for:
|
|
220
|
+
- Docker containers with `claude.bridge.enabled=true` label
|
|
221
|
+
- Running Docksal projects
|
|
222
|
+
- Running DDEV projects
|
|
223
|
+
|
|
224
|
+
#### `info` - Show Environment Information
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
claude-bridge info
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Displays:
|
|
231
|
+
- Detected environment (native, Docksal, DDEV, Lando, Docker)
|
|
232
|
+
- Platform information
|
|
233
|
+
- Network configuration
|
|
234
|
+
- Current configuration settings
|
|
235
|
+
|
|
236
|
+
## Configuration
|
|
237
|
+
|
|
238
|
+
### Configuration File
|
|
239
|
+
|
|
240
|
+
Create a configuration file at one of these locations:
|
|
241
|
+
|
|
242
|
+
1. `.claude-bridge.yml` (project root)
|
|
243
|
+
2. `~/.claude-bridge/config.yml` (user home)
|
|
244
|
+
|
|
245
|
+
### Configuration Options
|
|
246
|
+
|
|
247
|
+
```yaml
|
|
248
|
+
# Instance identification
|
|
249
|
+
instanceName: my-mac-desktop
|
|
250
|
+
mode: peer # host, client, or peer
|
|
251
|
+
|
|
252
|
+
# Server settings
|
|
253
|
+
listen:
|
|
254
|
+
port: 8766
|
|
255
|
+
host: 0.0.0.0
|
|
256
|
+
|
|
257
|
+
# Connection to remote bridge
|
|
258
|
+
connect:
|
|
259
|
+
url: ws://localhost:8765
|
|
260
|
+
hostGateway: true # Use host.docker.internal
|
|
261
|
+
|
|
262
|
+
# Context sharing settings
|
|
263
|
+
contextSharing:
|
|
264
|
+
autoSync: true
|
|
265
|
+
syncInterval: 5000 # milliseconds
|
|
266
|
+
maxChunkTokens: 4000
|
|
267
|
+
includePatterns:
|
|
268
|
+
- "src/**/*.ts"
|
|
269
|
+
- "src/**/*.tsx"
|
|
270
|
+
- "*.json"
|
|
271
|
+
excludePatterns:
|
|
272
|
+
- "node_modules/**"
|
|
273
|
+
- "dist/**"
|
|
274
|
+
- ".git/**"
|
|
275
|
+
|
|
276
|
+
# Interaction settings
|
|
277
|
+
interaction:
|
|
278
|
+
requireConfirmation: false
|
|
279
|
+
notifyOnActivity: true
|
|
280
|
+
taskTimeout: 300000 # 5 minutes in milliseconds
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Configuration Reference
|
|
284
|
+
|
|
285
|
+
| Setting | Type | Default | Description |
|
|
286
|
+
|---------|------|---------|-------------|
|
|
287
|
+
| `instanceName` | string | - | Unique name for this bridge instance |
|
|
288
|
+
| `mode` | string | - | Operation mode: `host`, `client`, or `peer` |
|
|
289
|
+
| `listen.port` | number | 8765 | Port to listen on |
|
|
290
|
+
| `listen.host` | string | 0.0.0.0 | Host to bind to |
|
|
291
|
+
| `connect.url` | string | - | WebSocket URL of remote bridge |
|
|
292
|
+
| `connect.hostGateway` | boolean | false | Use `host.docker.internal` |
|
|
293
|
+
| `contextSharing.autoSync` | boolean | true | Automatically sync context |
|
|
294
|
+
| `contextSharing.syncInterval` | number | 5000 | Sync interval in ms |
|
|
295
|
+
| `contextSharing.maxChunkTokens` | number | 4000 | Max tokens per context chunk |
|
|
296
|
+
| `contextSharing.includePatterns` | array | [...] | Glob patterns for included files |
|
|
297
|
+
| `contextSharing.excludePatterns` | array | [...] | Glob patterns for excluded files |
|
|
298
|
+
| `interaction.requireConfirmation` | boolean | false | Require user confirmation for tasks |
|
|
299
|
+
| `interaction.notifyOnActivity` | boolean | true | Show notifications on activity |
|
|
300
|
+
| `interaction.taskTimeout` | number | 300000 | Task timeout in ms |
|
|
301
|
+
|
|
302
|
+
## Environment Setup
|
|
303
|
+
|
|
304
|
+
### DDEV
|
|
305
|
+
|
|
306
|
+
**Option 1: Using the DDEV Addon**
|
|
307
|
+
|
|
308
|
+
Copy the addon files to your DDEV project:
|
|
309
|
+
|
|
310
|
+
```bash
|
|
311
|
+
cp -r addons/ddev/* .ddev/
|
|
312
|
+
ddev restart
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Then start the bridge:
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
ddev exec claude-bridge start --connect ws://host.docker.internal:8766
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**Option 2: Add to docker-compose**
|
|
322
|
+
|
|
323
|
+
Create `.ddev/docker-compose.claude-bridge.yaml`:
|
|
324
|
+
|
|
325
|
+
```yaml
|
|
326
|
+
services:
|
|
327
|
+
web:
|
|
328
|
+
labels:
|
|
329
|
+
- "claude.bridge.enabled=true"
|
|
330
|
+
- "claude.bridge.port=8765"
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Docksal
|
|
334
|
+
|
|
335
|
+
**Option 1: Using the Docksal Addon**
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
# Copy addon to Docksal
|
|
339
|
+
cp -r addons/docksal/* ~/.docksal/addons/claude-bridge/
|
|
340
|
+
|
|
341
|
+
# Install in your project
|
|
342
|
+
fin addon install claude-bridge
|
|
343
|
+
|
|
344
|
+
# Start the bridge
|
|
345
|
+
fin claude-bridge start
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**Option 2: Manual Setup**
|
|
349
|
+
|
|
350
|
+
Add to your project's `.docksal/docksal.yml`:
|
|
351
|
+
|
|
352
|
+
```yaml
|
|
353
|
+
services:
|
|
354
|
+
cli:
|
|
355
|
+
labels:
|
|
356
|
+
- "claude.bridge.enabled=true"
|
|
357
|
+
- "claude.bridge.port=8765"
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Lando
|
|
361
|
+
|
|
362
|
+
Lando support is coming soon. For now, you can manually install the bridge in your Lando container:
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
lando ssh
|
|
366
|
+
npm install -g claude-code-bridge
|
|
367
|
+
claude-bridge start --connect ws://host.docker.internal:8766
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Plain Docker
|
|
371
|
+
|
|
372
|
+
Add to your `docker-compose.yml`:
|
|
373
|
+
|
|
374
|
+
```yaml
|
|
375
|
+
services:
|
|
376
|
+
app:
|
|
377
|
+
labels:
|
|
378
|
+
- "claude.bridge.enabled=true"
|
|
379
|
+
- "claude.bridge.port=8765"
|
|
380
|
+
environment:
|
|
381
|
+
- NODE_ENV=development
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
Then inside the container:
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
npm install -g claude-code-bridge
|
|
388
|
+
claude-bridge start --auto
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
## Programmatic Usage
|
|
392
|
+
|
|
393
|
+
### Basic Usage
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
import { Bridge, BridgeConfig } from 'claude-code-bridge';
|
|
397
|
+
|
|
398
|
+
// Create bridge configuration
|
|
399
|
+
const config: BridgeConfig = {
|
|
400
|
+
mode: 'peer',
|
|
401
|
+
instanceName: 'my-bridge',
|
|
402
|
+
listen: { port: 8765, host: '0.0.0.0' },
|
|
403
|
+
connect: { url: 'ws://localhost:8766' },
|
|
404
|
+
contextSharing: {
|
|
405
|
+
autoSync: true,
|
|
406
|
+
syncInterval: 5000,
|
|
407
|
+
maxChunkTokens: 4000,
|
|
408
|
+
includePatterns: ['src/**/*.ts'],
|
|
409
|
+
excludePatterns: ['node_modules/**'],
|
|
410
|
+
},
|
|
411
|
+
interaction: {
|
|
412
|
+
requireConfirmation: false,
|
|
413
|
+
notifyOnActivity: true,
|
|
414
|
+
taskTimeout: 300000,
|
|
415
|
+
},
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
// Create and start bridge
|
|
419
|
+
const bridge = new Bridge(config);
|
|
420
|
+
await bridge.start();
|
|
421
|
+
|
|
422
|
+
// Get connected peers
|
|
423
|
+
const peers = bridge.getPeers();
|
|
424
|
+
console.log('Connected peers:', peers);
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Context Synchronization
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
// Send context to connected peers
|
|
431
|
+
await bridge.syncContext({
|
|
432
|
+
files: [
|
|
433
|
+
{ path: 'src/api.ts', content: 'export const api = {...}' },
|
|
434
|
+
{ path: 'src/types.ts', content: 'export interface User {...}' },
|
|
435
|
+
],
|
|
436
|
+
summary: 'API client implementation files',
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
// Handle incoming context
|
|
440
|
+
bridge.onContextReceived((context) => {
|
|
441
|
+
console.log('Received context:', context.summary);
|
|
442
|
+
for (const file of context.files || []) {
|
|
443
|
+
console.log(` - ${file.path}`);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
// Request specific context from peer
|
|
448
|
+
const chunks = await bridge.requestContext('authentication logic');
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### Task Delegation
|
|
452
|
+
|
|
453
|
+
```typescript
|
|
454
|
+
// Delegate a task to the connected peer
|
|
455
|
+
const result = await bridge.delegateTask({
|
|
456
|
+
id: 'task-001',
|
|
457
|
+
description: 'Refactor the UserService to use dependency injection',
|
|
458
|
+
scope: 'execute', // 'execute', 'analyze', or 'suggest'
|
|
459
|
+
constraints: ['Maintain backward compatibility', 'Add unit tests'],
|
|
460
|
+
timeout: 60000, // 1 minute
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
if (result.success) {
|
|
464
|
+
console.log('Task completed:', result.data);
|
|
465
|
+
for (const artifact of result.artifacts || []) {
|
|
466
|
+
console.log(` ${artifact.action}: ${artifact.path}`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Handle incoming tasks
|
|
471
|
+
bridge.onTaskReceived(async (task) => {
|
|
472
|
+
console.log('Received task:', task.description);
|
|
473
|
+
|
|
474
|
+
// Process the task...
|
|
475
|
+
|
|
476
|
+
return {
|
|
477
|
+
success: true,
|
|
478
|
+
data: { message: 'Task completed successfully' },
|
|
479
|
+
artifacts: [
|
|
480
|
+
{ path: 'src/UserService.ts', action: 'modified' },
|
|
481
|
+
],
|
|
482
|
+
};
|
|
483
|
+
});
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
### Environment Detection
|
|
487
|
+
|
|
488
|
+
```typescript
|
|
489
|
+
import { detectEnvironment, getHostGateway } from 'claude-code-bridge';
|
|
490
|
+
|
|
491
|
+
const env = detectEnvironment();
|
|
492
|
+
console.log('Environment:', env.type); // 'native', 'docksal', 'ddev', 'lando', 'docker'
|
|
493
|
+
console.log('Is Container:', env.isContainer);
|
|
494
|
+
console.log('Project Name:', env.projectName);
|
|
495
|
+
|
|
496
|
+
const gateway = getHostGateway();
|
|
497
|
+
console.log('Host Gateway:', gateway); // 'host.docker.internal' or IP address
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### Context Manager
|
|
501
|
+
|
|
502
|
+
```typescript
|
|
503
|
+
import { ContextManager } from 'claude-code-bridge';
|
|
504
|
+
|
|
505
|
+
const contextManager = new ContextManager({
|
|
506
|
+
rootPath: '/path/to/project',
|
|
507
|
+
includePatterns: ['src/**/*.ts', '*.json'],
|
|
508
|
+
excludePatterns: ['node_modules/**', 'dist/**'],
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
// Generate a project snapshot
|
|
512
|
+
const snapshot = await contextManager.generateSnapshot();
|
|
513
|
+
console.log('Project files:', snapshot.keyFiles);
|
|
514
|
+
|
|
515
|
+
// Get relevant context for a task
|
|
516
|
+
const chunks = await contextManager.getRelevantContext(
|
|
517
|
+
'user authentication',
|
|
518
|
+
4000 // max tokens
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
// Get changes since last sync
|
|
522
|
+
const delta = await contextManager.getDelta(previousSnapshotId);
|
|
523
|
+
for (const change of delta.changes) {
|
|
524
|
+
console.log(`${change.action}: ${change.path}`);
|
|
525
|
+
}
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
## Troubleshooting
|
|
529
|
+
|
|
530
|
+
### Connection Issues
|
|
531
|
+
|
|
532
|
+
**Problem:** Cannot connect to bridge from container
|
|
533
|
+
|
|
534
|
+
**Solutions:**
|
|
535
|
+
1. Ensure the host bridge is running: `claude-bridge status`
|
|
536
|
+
2. Check firewall settings allow the port
|
|
537
|
+
3. Verify `host.docker.internal` resolves: `ping host.docker.internal`
|
|
538
|
+
4. Try using the host IP directly: `claude-bridge connect ws://192.168.1.100:8766`
|
|
539
|
+
|
|
540
|
+
**Problem:** Connection keeps dropping
|
|
541
|
+
|
|
542
|
+
**Solutions:**
|
|
543
|
+
1. Check network stability
|
|
544
|
+
2. Increase timeout settings in config
|
|
545
|
+
3. Enable verbose logging: `claude-bridge start -v`
|
|
546
|
+
|
|
547
|
+
### Environment Detection Issues
|
|
548
|
+
|
|
549
|
+
**Problem:** Bridge doesn't detect my environment correctly
|
|
550
|
+
|
|
551
|
+
**Solutions:**
|
|
552
|
+
1. Run `claude-bridge info` to see detected environment
|
|
553
|
+
2. Check environment variables are set correctly:
|
|
554
|
+
- Docksal: `DOCKSAL_STACK` should be set
|
|
555
|
+
- DDEV: `IS_DDEV_PROJECT=true` should be set
|
|
556
|
+
- Lando: `LANDO=ON` should be set
|
|
557
|
+
3. Use explicit configuration instead of auto-detection
|
|
558
|
+
|
|
559
|
+
### Port Conflicts
|
|
560
|
+
|
|
561
|
+
**Problem:** Port already in use
|
|
562
|
+
|
|
563
|
+
**Solutions:**
|
|
564
|
+
1. Use a different port: `claude-bridge start --port 9000`
|
|
565
|
+
2. Find and stop the process using the port:
|
|
566
|
+
```bash
|
|
567
|
+
lsof -i :8765
|
|
568
|
+
kill <PID>
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
### Debugging
|
|
572
|
+
|
|
573
|
+
Enable verbose logging for detailed output:
|
|
574
|
+
|
|
575
|
+
```bash
|
|
576
|
+
claude-bridge start -v
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
Or set the log level via environment variable:
|
|
580
|
+
|
|
581
|
+
```bash
|
|
582
|
+
LOG_LEVEL=debug claude-bridge start
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
## Development
|
|
586
|
+
|
|
587
|
+
### Prerequisites
|
|
588
|
+
|
|
589
|
+
- Node.js 20+
|
|
590
|
+
- npm or pnpm
|
|
591
|
+
|
|
592
|
+
### Setup
|
|
593
|
+
|
|
594
|
+
```bash
|
|
595
|
+
# Clone the repository
|
|
596
|
+
git clone https://github.com/willjackson/claude-code-bridge.git
|
|
597
|
+
cd claude-code-bridge
|
|
598
|
+
|
|
599
|
+
# Install dependencies
|
|
600
|
+
npm install
|
|
601
|
+
|
|
602
|
+
# Build
|
|
603
|
+
npm run build
|
|
604
|
+
|
|
605
|
+
# Run tests
|
|
606
|
+
npm test
|
|
607
|
+
|
|
608
|
+
# Run tests in watch mode
|
|
609
|
+
npm run test:watch
|
|
610
|
+
|
|
611
|
+
# Type checking
|
|
612
|
+
npm run lint
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Project Structure
|
|
616
|
+
|
|
617
|
+
```
|
|
618
|
+
claude-code-bridge/
|
|
619
|
+
├── src/
|
|
620
|
+
│ ├── index.ts # Main exports
|
|
621
|
+
│ ├── bridge/
|
|
622
|
+
│ │ ├── core.ts # Bridge class
|
|
623
|
+
│ │ ├── protocol.ts # Message types & validation
|
|
624
|
+
│ │ ├── messages.ts # Message builders
|
|
625
|
+
│ │ └── context.ts # Context manager
|
|
626
|
+
│ ├── transport/
|
|
627
|
+
│ │ ├── interface.ts # Transport abstraction
|
|
628
|
+
│ │ ├── websocket.ts # WebSocket implementation
|
|
629
|
+
│ │ └── discovery.ts # Peer discovery
|
|
630
|
+
│ ├── environment/
|
|
631
|
+
│ │ ├── detect.ts # Environment detection
|
|
632
|
+
│ │ ├── docksal.ts # Docksal helpers
|
|
633
|
+
│ │ ├── ddev.ts # DDEV helpers
|
|
634
|
+
│ │ └── lando.ts # Lando helpers
|
|
635
|
+
│ ├── cli/
|
|
636
|
+
│ │ ├── index.ts # CLI entry point
|
|
637
|
+
│ │ └── commands/ # CLI commands
|
|
638
|
+
│ └── utils/
|
|
639
|
+
│ ├── logger.ts # Logging utility
|
|
640
|
+
│ ├── config.ts # Configuration loading
|
|
641
|
+
│ └── tokens.ts # Token estimation
|
|
642
|
+
├── tests/
|
|
643
|
+
│ ├── unit/ # Unit tests
|
|
644
|
+
│ ├── integration/ # Integration tests
|
|
645
|
+
│ └── e2e/ # End-to-end tests
|
|
646
|
+
└── addons/
|
|
647
|
+
├── ddev/ # DDEV addon
|
|
648
|
+
├── docksal/ # Docksal addon
|
|
649
|
+
└── lando/ # Lando plugin
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
### Running Tests
|
|
653
|
+
|
|
654
|
+
```bash
|
|
655
|
+
# Run all tests
|
|
656
|
+
npm test
|
|
657
|
+
|
|
658
|
+
# Run with coverage
|
|
659
|
+
npm run test:coverage
|
|
660
|
+
|
|
661
|
+
# Run specific test file
|
|
662
|
+
npm test -- tests/unit/bridge/protocol.test.ts
|
|
663
|
+
|
|
664
|
+
# Run tests matching pattern
|
|
665
|
+
npm test -- --grep "WebSocket"
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
## Documentation
|
|
669
|
+
|
|
670
|
+
- [CLAUDE.md](./CLAUDE.md) - Detailed project specification and architecture
|
|
671
|
+
- [AGENTS.md](./AGENTS.md) - Guidelines for AI agents working on this codebase
|
|
672
|
+
- [instructions.md](./instructions.md) - Development phases and testing strategy
|
|
673
|
+
|
|
674
|
+
## License
|
|
675
|
+
|
|
676
|
+
MIT License - see [LICENSE](./LICENSE) for details.
|
|
677
|
+
|
|
678
|
+
## Contributing
|
|
679
|
+
|
|
680
|
+
1. Fork the repository
|
|
681
|
+
2. Create a feature branch: `git checkout -b feature/my-feature`
|
|
682
|
+
3. Make your changes
|
|
683
|
+
4. Run tests: `npm test`
|
|
684
|
+
5. Commit: `git commit -m 'Add my feature'`
|
|
685
|
+
6. Push: `git push origin feature/my-feature`
|
|
686
|
+
7. Open a Pull Request
|
|
687
|
+
|
|
688
|
+
## Support
|
|
689
|
+
|
|
690
|
+
- GitHub Issues: [Report a bug or request a feature](https://github.com/willjackson/claude-code-bridge/issues)
|