@raysonmeng/agentbridge 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/.claude-plugin/marketplace.json +24 -0
- package/LICENSE +21 -0
- package/README.md +291 -0
- package/README.zh-CN.md +291 -0
- package/dist/cli.js +1158 -0
- package/package.json +54 -0
- package/plugins/agentbridge/.claude-plugin/plugin.json +12 -0
- package/plugins/agentbridge/.mcp.json +11 -0
- package/plugins/agentbridge/README.md +43 -0
- package/plugins/agentbridge/commands/init.md +70 -0
- package/plugins/agentbridge/hooks/hooks.json +16 -0
- package/plugins/agentbridge/scripts/health-check.sh +51 -0
- package/plugins/agentbridge/server/bridge-server.js +14734 -0
- package/plugins/agentbridge/server/daemon.js +1762 -0
- package/scripts/postinstall.cjs +27 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agentbridge",
|
|
3
|
+
"owner": {
|
|
4
|
+
"name": "AgentBridge Contributors",
|
|
5
|
+
"email": "raysonmeng@qq.com",
|
|
6
|
+
"url": "https://github.com/raysonmeng/agent-bridge"
|
|
7
|
+
},
|
|
8
|
+
"metadata": {
|
|
9
|
+
"description": "Marketplace for the AgentBridge Claude Code plugin and supporting runtime integration."
|
|
10
|
+
},
|
|
11
|
+
"plugins": [
|
|
12
|
+
{
|
|
13
|
+
"name": "agentbridge",
|
|
14
|
+
"description": "Bridge Claude Code and Codex through a shared daemon, push channel delivery, and reply/get_messages tools.",
|
|
15
|
+
"version": "0.1.0",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "AgentBridge Contributors",
|
|
18
|
+
"email": "raysonmeng@qq.com"
|
|
19
|
+
},
|
|
20
|
+
"source": "./plugins/agentbridge",
|
|
21
|
+
"category": "development"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AgentBridge Contributors
|
|
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,291 @@
|
|
|
1
|
+
# AgentBridge
|
|
2
|
+
|
|
3
|
+
[](https://github.com/raysonmeng/agent-bridge/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
[中文文档](README.zh-CN.md)
|
|
7
|
+
|
|
8
|
+
Local bridge for bidirectional communication between Claude Code and Codex inside the same working session.
|
|
9
|
+
|
|
10
|
+
AgentBridge uses a two-process architecture:
|
|
11
|
+
|
|
12
|
+
- **bridge.ts** is the foreground MCP client started by Claude Code via the AgentBridge plugin
|
|
13
|
+
- **daemon.ts** is a persistent local background process that owns the Codex app-server proxy and bridge state
|
|
14
|
+
|
|
15
|
+
When Claude Code closes, the foreground MCP process exits while the background daemon and Codex proxy keep running. When Claude Code starts again, it reconnects automatically with exponential backoff.
|
|
16
|
+
|
|
17
|
+
## What this project is / is not
|
|
18
|
+
|
|
19
|
+
**This project is:**
|
|
20
|
+
|
|
21
|
+
- A local developer tool for connecting Claude Code and Codex in one workflow
|
|
22
|
+
- A bridge that forwards messages between an MCP channel and the Codex app-server protocol
|
|
23
|
+
- An experimental setup for human-in-the-loop collaboration between multiple agents
|
|
24
|
+
|
|
25
|
+
**This project is not:**
|
|
26
|
+
|
|
27
|
+
- A hosted service or multi-tenant system
|
|
28
|
+
- A generic orchestration framework for arbitrary agent backends
|
|
29
|
+
- A hardened security boundary between tools you do not trust
|
|
30
|
+
|
|
31
|
+
## Architecture
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
┌──────────────┐ MCP stdio / plugin ┌────────────────────┐
|
|
35
|
+
│ Claude Code │ ──────────────────────────▶ │ bridge.ts │
|
|
36
|
+
│ Session │ ◀────────────────────────── │ foreground client │
|
|
37
|
+
└──────────────┘ └─────────┬──────────┘
|
|
38
|
+
│
|
|
39
|
+
│ control WS (:4502)
|
|
40
|
+
▼
|
|
41
|
+
┌────────────────────┐
|
|
42
|
+
│ daemon.ts │
|
|
43
|
+
│ bridge daemon │
|
|
44
|
+
└─────────┬──────────┘
|
|
45
|
+
│
|
|
46
|
+
ws://127.0.0.1:4501 proxy
|
|
47
|
+
│
|
|
48
|
+
▼
|
|
49
|
+
┌────────────────────┐
|
|
50
|
+
│ Codex app-server │
|
|
51
|
+
└────────────────────┘
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Data flow
|
|
55
|
+
|
|
56
|
+
| Direction | Path |
|
|
57
|
+
|-----------|------|
|
|
58
|
+
| **Codex -> Claude** | `daemon.ts` captures `agentMessage` -> control WS -> `bridge.ts` -> `notifications/claude/channel` |
|
|
59
|
+
| **Claude -> Codex** | Claude calls the `reply` tool -> `bridge.ts` -> control WS -> `daemon.ts` -> `turn/start` injects into the Codex thread |
|
|
60
|
+
|
|
61
|
+
### Loop prevention
|
|
62
|
+
|
|
63
|
+
Each message carries a `source` field (`"claude"` or `"codex"`). The bridge never forwards a message back to its origin.
|
|
64
|
+
|
|
65
|
+
## Prerequisites
|
|
66
|
+
|
|
67
|
+
| Dependency | Version | Install |
|
|
68
|
+
|-----------|---------|---------|
|
|
69
|
+
| [Bun](https://bun.sh) | v1.0+ | `curl -fsSL https://bun.sh/install \| bash` |
|
|
70
|
+
| [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | v2.1.80+ | `npm install -g @anthropic-ai/claude-code` |
|
|
71
|
+
| [Codex CLI](https://github.com/openai/codex) | latest | `npm install -g @openai/codex` |
|
|
72
|
+
|
|
73
|
+
> **Note:** Bun is required as the runtime for the AgentBridge daemon and plugin server. Node.js alone is not sufficient.
|
|
74
|
+
|
|
75
|
+
## Quick Start
|
|
76
|
+
|
|
77
|
+
### Install via Plugin Marketplace (recommended)
|
|
78
|
+
|
|
79
|
+
Install AgentBridge directly from Claude Code using the plugin marketplace:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# 1. In Claude Code, add the AgentBridge marketplace
|
|
83
|
+
/plugin marketplace add raysonmeng/agent-bridge
|
|
84
|
+
|
|
85
|
+
# 2. Install the plugin
|
|
86
|
+
/plugin install agentbridge@agentbridge
|
|
87
|
+
|
|
88
|
+
# 3. Reload plugins to activate
|
|
89
|
+
/reload-plugins
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then install the CLI tool:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# 4. Install the CLI globally
|
|
96
|
+
npm install -g agentbridge
|
|
97
|
+
|
|
98
|
+
# 5. Generate project config (optional)
|
|
99
|
+
abg init
|
|
100
|
+
|
|
101
|
+
# 6. Start Claude Code with AgentBridge channel enabled
|
|
102
|
+
abg claude
|
|
103
|
+
|
|
104
|
+
# 7. Start Codex TUI connected to the bridge (in another terminal)
|
|
105
|
+
abg codex
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
> **Tip:** `abg` is a short alias for `agentbridge`. Both commands are identical — use whichever you prefer.
|
|
109
|
+
|
|
110
|
+
That's it. The daemon starts automatically when needed and reconnects if restarted.
|
|
111
|
+
|
|
112
|
+
#### Updating the plugin
|
|
113
|
+
|
|
114
|
+
When a new version is released, update from Claude Code:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
/plugin marketplace update agentbridge
|
|
118
|
+
/reload-plugins
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Or enable auto-update: run `/plugin` → **Marketplaces** tab → select **agentbridge** → **Enable auto-update**.
|
|
122
|
+
|
|
123
|
+
### Install for local development
|
|
124
|
+
|
|
125
|
+
If you want to modify AgentBridge source code, use the local development setup instead:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# 1. Clone and install dependencies
|
|
129
|
+
git clone https://github.com/raysonmeng/agent-bridge.git
|
|
130
|
+
cd agent-bridge
|
|
131
|
+
bun install
|
|
132
|
+
bun link
|
|
133
|
+
|
|
134
|
+
# 2. Set up local plugin + project config
|
|
135
|
+
agentbridge dev # Register local marketplace + install plugin
|
|
136
|
+
agentbridge init # Check dependencies, generate .agentbridge/config.json
|
|
137
|
+
|
|
138
|
+
# 3. Start Claude Code with AgentBridge plugin loaded
|
|
139
|
+
agentbridge claude
|
|
140
|
+
|
|
141
|
+
# 4. Start Codex TUI connected to the bridge (in another terminal)
|
|
142
|
+
agentbridge codex
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
> **Note:** `agentbridge claude` injects `--dangerously-load-development-channels plugin:agentbridge@agentbridge` automatically. This loads a local development channel into Claude Code (currently a Research Preview workflow). Only enable channels and MCP servers you trust.
|
|
146
|
+
|
|
147
|
+
#### Updating after code changes
|
|
148
|
+
|
|
149
|
+
After modifying AgentBridge source code, re-run `agentbridge dev` to sync changes to the plugin cache, then restart Claude Code or run `/reload-plugins` in an active session.
|
|
150
|
+
|
|
151
|
+
## CLI Reference
|
|
152
|
+
|
|
153
|
+
> All commands work with both `agentbridge` and the short alias `abg`.
|
|
154
|
+
|
|
155
|
+
| Command | Description |
|
|
156
|
+
|---------|-------------|
|
|
157
|
+
| `abg init` | Install plugin, check dependencies (bun/claude/codex), generate `.agentbridge/config.json` and `collaboration.md` |
|
|
158
|
+
| `abg claude [args...]` | Start Claude Code with push channel enabled. Clears any killed sentinel from a previous `kill`. Pass-through args are forwarded to `claude` |
|
|
159
|
+
| `abg codex [args...]` | Start Codex TUI connected to AgentBridge daemon. Manages TUI process lifecycle (pid tracking, cleanup). Pass-through args forwarded to `codex` |
|
|
160
|
+
| `abg kill` | Gracefully stop both daemon and managed Codex TUI, clean up state files, write killed sentinel |
|
|
161
|
+
| `abg dev` | (Dev only) Register local marketplace + force-sync plugin to cache |
|
|
162
|
+
| `abg --help` | Show help |
|
|
163
|
+
| `abg --version` | Show version |
|
|
164
|
+
|
|
165
|
+
### Owned flags
|
|
166
|
+
|
|
167
|
+
Some flags are automatically injected and cannot be manually specified:
|
|
168
|
+
|
|
169
|
+
- `agentbridge claude` owns: `--channels`, `--dangerously-load-development-channels`
|
|
170
|
+
- `agentbridge codex` owns: `--remote`, `--enable tui_app_server`
|
|
171
|
+
|
|
172
|
+
Passing these flags manually will result in a hard error with guidance to use the native command directly.
|
|
173
|
+
|
|
174
|
+
## Project Config
|
|
175
|
+
|
|
176
|
+
Running `agentbridge init` creates a `.agentbridge/` directory in your project root:
|
|
177
|
+
|
|
178
|
+
| File | Purpose |
|
|
179
|
+
|------|---------|
|
|
180
|
+
| `config.json` | Machine-readable project config (ports, agent roles, markers, turn coordination) |
|
|
181
|
+
| `collaboration.md` | Human/agent-readable collaboration rules (roles, thinking patterns, communication style) |
|
|
182
|
+
|
|
183
|
+
The config is loaded by the CLI and daemon at startup. Re-running `init` is idempotent and will not overwrite existing files.
|
|
184
|
+
|
|
185
|
+
## File Structure
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
agent_bridge/
|
|
189
|
+
├── .github/
|
|
190
|
+
│ ├── ISSUE_TEMPLATE/ # Bug report and feature request templates
|
|
191
|
+
│ ├── pull_request_template.md
|
|
192
|
+
│ └── workflows/ci.yml # GitHub Actions CI
|
|
193
|
+
├── assets/ # Static assets (images, etc.)
|
|
194
|
+
├── docs/
|
|
195
|
+
│ ├── phase3-spec.md # Phase 3 design spec (CLI + Plugin)
|
|
196
|
+
│ ├── v1-roadmap.md # v1 feature roadmap
|
|
197
|
+
│ └── v2-architecture.md # v2 multi-agent architecture design
|
|
198
|
+
├── plugins/agentbridge/ # Claude Code plugin bundle
|
|
199
|
+
│ ├── .claude-plugin/plugin.json
|
|
200
|
+
│ ├── commands/init.md
|
|
201
|
+
│ ├── hooks/hooks.json
|
|
202
|
+
│ ├── scripts/health-check.sh
|
|
203
|
+
│ └── server/ # Bundled bridge-server.js + daemon.js
|
|
204
|
+
├── src/
|
|
205
|
+
│ ├── bridge.ts # Claude foreground MCP client (plugin entry point)
|
|
206
|
+
│ ├── daemon.ts # Persistent background daemon
|
|
207
|
+
│ ├── daemon-client.ts # WebSocket client for daemon control port
|
|
208
|
+
│ ├── daemon-lifecycle.ts # Shared daemon lifecycle (ensureRunning, kill, startup lock)
|
|
209
|
+
│ ├── control-protocol.ts # Foreground/background control protocol types
|
|
210
|
+
│ ├── claude-adapter.ts # MCP server adapter for Claude Code channels
|
|
211
|
+
│ ├── codex-adapter.ts # Codex app-server WebSocket proxy and message interception
|
|
212
|
+
│ ├── config-service.ts # Project config (.agentbridge/) read/write
|
|
213
|
+
│ ├── state-dir.ts # Platform-aware state directory resolver
|
|
214
|
+
│ ├── message-filter.ts # Smart message filtering (markers, summary buffer)
|
|
215
|
+
│ ├── types.ts # Shared types
|
|
216
|
+
│ ├── cli.ts # CLI entry point and command router
|
|
217
|
+
│ └── cli/
|
|
218
|
+
│ ├── init.ts # agentbridge init
|
|
219
|
+
│ ├── claude.ts # agentbridge claude
|
|
220
|
+
│ ├── codex.ts # agentbridge codex
|
|
221
|
+
│ ├── kill.ts # agentbridge kill
|
|
222
|
+
│ └── dev.ts # agentbridge dev
|
|
223
|
+
├── CLAUDE.md # Project rules for AI agents
|
|
224
|
+
├── CODE_OF_CONDUCT.md
|
|
225
|
+
├── CONTRIBUTING.md
|
|
226
|
+
├── LICENSE
|
|
227
|
+
├── README.md
|
|
228
|
+
├── README.zh-CN.md
|
|
229
|
+
├── SECURITY.md
|
|
230
|
+
├── package.json
|
|
231
|
+
└── tsconfig.json
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Configuration
|
|
235
|
+
|
|
236
|
+
### Environment Variables
|
|
237
|
+
|
|
238
|
+
| Variable | Default | Description |
|
|
239
|
+
|----------|---------|-------------|
|
|
240
|
+
| `CODEX_WS_PORT` | `4500` | Codex app-server WebSocket port |
|
|
241
|
+
| `CODEX_PROXY_PORT` | `4501` | Bridge proxy port for the Codex TUI |
|
|
242
|
+
| `AGENTBRIDGE_CONTROL_PORT` | `4502` | Control port between bridge.ts and daemon.ts |
|
|
243
|
+
| `AGENTBRIDGE_STATE_DIR` | Platform default | State directory for pid, status, logs (macOS: `~/Library/Application Support/agentbridge/`, Linux: `$XDG_STATE_HOME/agentbridge/`) |
|
|
244
|
+
| `AGENTBRIDGE_MODE` | `push` | Message delivery mode (`push` for channels, `pull` for API key mode) |
|
|
245
|
+
| `AGENTBRIDGE_DAEMON_ENTRY` | `./daemon.ts` | Override daemon entry point (used by plugin bundles) |
|
|
246
|
+
|
|
247
|
+
### State Directory
|
|
248
|
+
|
|
249
|
+
The daemon stores runtime state in a platform-aware directory:
|
|
250
|
+
|
|
251
|
+
| Platform | Default Path |
|
|
252
|
+
|----------|-------------|
|
|
253
|
+
| macOS | `~/Library/Application Support/agentbridge/` |
|
|
254
|
+
| Linux | `$XDG_STATE_HOME/agentbridge/` (fallback: `~/.local/state/agentbridge/`) |
|
|
255
|
+
|
|
256
|
+
Contents: `daemon.pid`, `status.json`, `agentbridge.log`, `killed` (sentinel), `startup.lock`
|
|
257
|
+
|
|
258
|
+
## Current Limitations
|
|
259
|
+
|
|
260
|
+
- Only forwards `agentMessage` items, not intermediate `commandExecution`, `fileChange`, or similar events
|
|
261
|
+
- Single Codex thread, no multi-session support yet
|
|
262
|
+
- Single Claude foreground connection; a new Claude session replaces the previous one
|
|
263
|
+
- Fixed ports mean only one AgentBridge instance per machine (multi-project support planned for post-v1)
|
|
264
|
+
|
|
265
|
+
### Codex git restrictions
|
|
266
|
+
|
|
267
|
+
Codex runs in a sandboxed environment that **blocks all writes to the `.git` directory**. This means Codex cannot run `git commit`, `git push`, `git pull`, `git checkout -b`, `git merge`, or any other command that modifies git metadata. Attempting these commands will cause the Codex session to hang indefinitely.
|
|
268
|
+
|
|
269
|
+
**Recommendation:** Let Claude Code handle all git operations (branching, committing, pushing, creating PRs). Codex should focus on code changes and report completed work via `agentMessage`, then Claude Code takes care of the git workflow.
|
|
270
|
+
|
|
271
|
+
## Roadmap
|
|
272
|
+
|
|
273
|
+
- **v1.x (current)**: Improve the single-bridge experience without architectural refactoring -- less noise, better turn discipline, and clearer collaboration modes. See [docs/v1-roadmap.md](docs/v1-roadmap.md).
|
|
274
|
+
- **v2 (planned)**: Introduce the multi-agent foundation -- room-scoped collaboration, stable identity, a formal control protocol, and stronger recovery semantics. See [docs/v2-architecture.md](docs/v2-architecture.md).
|
|
275
|
+
- **v3+ (longer term)**: Explore smarter collaboration, richer policies, and more advanced orchestration across runtimes.
|
|
276
|
+
|
|
277
|
+
## How This Project Was Built
|
|
278
|
+
|
|
279
|
+
This project was built collaboratively by **Claude Code** (Anthropic) and **Codex** (OpenAI), communicating through AgentBridge itself -- the very tool they were building together. A human developer coordinated the effort, assigning tasks, reviewing progress, and directing the two agents to work in parallel and review each other's output.
|
|
280
|
+
|
|
281
|
+
In other words, AgentBridge is its own proof of concept: two AI agents from different providers, connected in real time, shipping code side by side.
|
|
282
|
+
|
|
283
|
+
## Contact
|
|
284
|
+
|
|
285
|
+
This is my first open-source project! I'd love to connect with anyone interested in multi-agent collaboration, AI tooling, or just building cool things together. Feel free to reach out:
|
|
286
|
+
|
|
287
|
+
- **Twitter/X**: [@raysonmeng](https://x.com/raysonmeng)
|
|
288
|
+
- **Xiaohongshu**: [Profile](https://www.xiaohongshu.com/user/profile/62a3709d0000000021028b7e)
|
|
289
|
+
- **WeChat**: Scan the QR code below to add me
|
|
290
|
+
|
|
291
|
+
<img src="assets/wechat-qr.jpg" alt="WeChat QR Code" width="300" />
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
# AgentBridge
|
|
2
|
+
|
|
3
|
+
English version: [README.md](README.md)
|
|
4
|
+
|
|
5
|
+
[](https://github.com/raysonmeng/agent-bridge/actions/workflows/ci.yml)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
让 Claude Code 和 Codex 在同一个工作会话中进行双向通信的本地 Bridge。
|
|
9
|
+
|
|
10
|
+
AgentBridge 采用两层进程结构:
|
|
11
|
+
|
|
12
|
+
- **bridge.ts** 是由 Claude Code 通过 AgentBridge 插件启动的前台 MCP 客户端
|
|
13
|
+
- **daemon.ts** 是常驻本地的后台进程,持有 Codex app-server 代理和桥接状态
|
|
14
|
+
|
|
15
|
+
当 Claude Code 关闭时,前台 MCP 进程退出,后台 daemon 与 Codex 代理继续存活。当 Claude Code 再次启动时,会自动重连(指数退避)。
|
|
16
|
+
|
|
17
|
+
## 这个项目是什么 / 不是什么
|
|
18
|
+
|
|
19
|
+
**这个项目是:**
|
|
20
|
+
|
|
21
|
+
- 一个把 Claude Code 和 Codex 连接到同一工作流里的本地开发工具
|
|
22
|
+
- 一个在 MCP channel 与 Codex app-server 协议之间转发消息的桥接层
|
|
23
|
+
- 一个面向人工参与、多代理协作场景的实验性方案
|
|
24
|
+
|
|
25
|
+
**这个项目不是:**
|
|
26
|
+
|
|
27
|
+
- 一个托管服务或多租户系统
|
|
28
|
+
- 一个面向任意 Agent 后端的通用编排框架
|
|
29
|
+
- 一个可以隔离不可信工具的强化安全边界
|
|
30
|
+
|
|
31
|
+
## 架构
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
┌──────────────┐ MCP stdio / plugin ┌────────────────────┐
|
|
35
|
+
│ Claude Code │ ─────────────────────────▶ │ bridge.ts │
|
|
36
|
+
│ Session │ ◀───────────────────────── │ 前台 MCP 客户端 │
|
|
37
|
+
└──────────────┘ └─────────┬──────────┘
|
|
38
|
+
│
|
|
39
|
+
│ 控制 WS (:4502)
|
|
40
|
+
▼
|
|
41
|
+
┌────────────────────┐
|
|
42
|
+
│ daemon.ts │
|
|
43
|
+
│ 常驻后台桥接进程 │
|
|
44
|
+
└─────────┬──────────┘
|
|
45
|
+
│
|
|
46
|
+
ws://127.0.0.1:4501 proxy
|
|
47
|
+
│
|
|
48
|
+
▼
|
|
49
|
+
┌────────────────────┐
|
|
50
|
+
│ Codex app-server │
|
|
51
|
+
└────────────────────┘
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 数据流
|
|
55
|
+
|
|
56
|
+
| 方向 | 链路 |
|
|
57
|
+
|------|------|
|
|
58
|
+
| **Codex -> Claude** | `daemon.ts` 捕获 `agentMessage` -> 控制 WS -> `bridge.ts` -> `notifications/claude/channel` |
|
|
59
|
+
| **Claude -> Codex** | Claude 调用 `reply` tool -> `bridge.ts` -> 控制 WS -> `daemon.ts` -> `turn/start` 注入 Codex thread |
|
|
60
|
+
|
|
61
|
+
### 防循环
|
|
62
|
+
|
|
63
|
+
每条消息都携带 `source` 字段(`"claude"` 或 `"codex"`),Bridge 永远不会把消息转发回它的来源。
|
|
64
|
+
|
|
65
|
+
## 前置条件
|
|
66
|
+
|
|
67
|
+
| 依赖 | 版本 | 安装方式 |
|
|
68
|
+
|------|------|----------|
|
|
69
|
+
| [Bun](https://bun.sh) | v1.0+ | `curl -fsSL https://bun.sh/install \| bash` |
|
|
70
|
+
| [Claude Code](https://docs.anthropic.com/en/docs/claude-code) | v2.1.80+ | `npm install -g @anthropic-ai/claude-code` |
|
|
71
|
+
| [Codex CLI](https://github.com/openai/codex) | latest | `npm install -g @openai/codex` |
|
|
72
|
+
|
|
73
|
+
> **注意:** Bun 是 AgentBridge daemon 和插件服务器的必要运行时,仅有 Node.js 不够。
|
|
74
|
+
|
|
75
|
+
## Quick Start
|
|
76
|
+
|
|
77
|
+
### 通过插件市场安装(推荐)
|
|
78
|
+
|
|
79
|
+
在 Claude Code 中直接安装 AgentBridge 插件:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# 1. 在 Claude Code 中,添加 AgentBridge 市场
|
|
83
|
+
/plugin marketplace add raysonmeng/agent-bridge
|
|
84
|
+
|
|
85
|
+
# 2. 安装插件
|
|
86
|
+
/plugin install agentbridge@agentbridge
|
|
87
|
+
|
|
88
|
+
# 3. 重新加载插件以激活
|
|
89
|
+
/reload-plugins
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
然后安装 CLI 工具:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# 4. 全局安装 CLI
|
|
96
|
+
npm install -g agentbridge
|
|
97
|
+
|
|
98
|
+
# 5. 生成项目配置(可选)
|
|
99
|
+
abg init
|
|
100
|
+
|
|
101
|
+
# 6. 启动 Claude Code(自动加载 AgentBridge channel)
|
|
102
|
+
abg claude
|
|
103
|
+
|
|
104
|
+
# 7. 在另一个终端启动 Codex TUI 连接 Bridge
|
|
105
|
+
abg codex
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
> **提示:** `abg` 是 `agentbridge` 的简写别名,两个命令完全等价,用哪个都行。
|
|
109
|
+
|
|
110
|
+
就这样。Daemon 会在需要时自动启动,重启后自动重连。
|
|
111
|
+
|
|
112
|
+
#### 更新插件
|
|
113
|
+
|
|
114
|
+
新版本发布后,在 Claude Code 中更新:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
/plugin marketplace update agentbridge
|
|
118
|
+
/reload-plugins
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
或启用自动更新:执行 `/plugin` → **Marketplaces** 标签页 → 选择 **agentbridge** → **Enable auto-update**。
|
|
122
|
+
|
|
123
|
+
### 本地开发安装
|
|
124
|
+
|
|
125
|
+
如需修改 AgentBridge 源码,使用本地开发模式:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# 1. 克隆并安装依赖
|
|
129
|
+
git clone https://github.com/raysonmeng/agent-bridge.git
|
|
130
|
+
cd agent-bridge
|
|
131
|
+
bun install
|
|
132
|
+
bun link
|
|
133
|
+
|
|
134
|
+
# 2. 安装本地插件 + 生成项目配置
|
|
135
|
+
agentbridge dev # 注册本地 marketplace + 安装插件
|
|
136
|
+
agentbridge init # 检查依赖、生成 .agentbridge/config.json
|
|
137
|
+
|
|
138
|
+
# 3. 启动 Claude Code(自动加载 AgentBridge 插件)
|
|
139
|
+
agentbridge claude
|
|
140
|
+
|
|
141
|
+
# 4. 在另一个终端启动 Codex TUI 连接 Bridge
|
|
142
|
+
agentbridge codex
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
> **注意:** `agentbridge claude` 会自动注入 `--dangerously-load-development-channels plugin:agentbridge@agentbridge`。这会把本地开发中的 channel 挂载进 Claude Code(当前属于 Research Preview)。请只启用你信任的 channel 和 MCP server。
|
|
146
|
+
|
|
147
|
+
#### 修改代码后更新
|
|
148
|
+
|
|
149
|
+
修改 AgentBridge 源码后,重新执行 `agentbridge dev` 同步插件到缓存,然后重启 Claude Code 或在活跃会话中执行 `/reload-plugins`。
|
|
150
|
+
|
|
151
|
+
## CLI 命令参考
|
|
152
|
+
|
|
153
|
+
> 所有命令同时支持 `agentbridge` 和简写别名 `abg`。
|
|
154
|
+
|
|
155
|
+
| 命令 | 说明 |
|
|
156
|
+
|------|------|
|
|
157
|
+
| `abg init` | 安装插件、检查依赖(bun/claude/codex)、生成 `.agentbridge/config.json` 和 `collaboration.md` |
|
|
158
|
+
| `abg claude [args...]` | 启动 Claude Code 并启用 push channel。自动清除之前 `kill` 留下的 sentinel。额外参数透传给 `claude` |
|
|
159
|
+
| `abg codex [args...]` | 启动连接到 AgentBridge daemon 的 Codex TUI。管理 TUI 进程生命周期(pid 跟踪、清理)。额外参数透传给 `codex` |
|
|
160
|
+
| `abg kill` | 优雅停止 daemon 和托管的 Codex TUI,清理状态文件,写入 killed sentinel |
|
|
161
|
+
| `abg dev` | (开发用)注册本地 marketplace + 强制同步插件到缓存 |
|
|
162
|
+
| `abg --help` | 显示帮助 |
|
|
163
|
+
| `abg --version` | 显示版本 |
|
|
164
|
+
|
|
165
|
+
### Owned flags
|
|
166
|
+
|
|
167
|
+
部分参数由 CLI 自动注入,不可手动指定:
|
|
168
|
+
|
|
169
|
+
- `agentbridge claude` 拥有:`--channels`、`--dangerously-load-development-channels`
|
|
170
|
+
- `agentbridge codex` 拥有:`--remote`、`--enable tui_app_server`
|
|
171
|
+
|
|
172
|
+
手动传入这些参数会报错,并提示使用原生命令。
|
|
173
|
+
|
|
174
|
+
## 项目配置
|
|
175
|
+
|
|
176
|
+
运行 `agentbridge init` 会在项目根目录创建 `.agentbridge/` 目录:
|
|
177
|
+
|
|
178
|
+
| 文件 | 用途 |
|
|
179
|
+
|------|------|
|
|
180
|
+
| `config.json` | 机器可读的项目配置(端口、Agent 角色、消息标记、回合协调) |
|
|
181
|
+
| `collaboration.md` | 人类/Agent 可读的协作规则(角色、思考模式、沟通风格) |
|
|
182
|
+
|
|
183
|
+
CLI 和 daemon 启动时会加载该配置。重复运行 `init` 是幂等的,不会覆盖已有文件。
|
|
184
|
+
|
|
185
|
+
## 文件结构
|
|
186
|
+
|
|
187
|
+
```
|
|
188
|
+
agent_bridge/
|
|
189
|
+
├── .github/
|
|
190
|
+
│ ├── ISSUE_TEMPLATE/ # Bug report 和 feature request 模板
|
|
191
|
+
│ ├── pull_request_template.md
|
|
192
|
+
│ └── workflows/ci.yml # GitHub Actions CI
|
|
193
|
+
├── assets/ # 图片资源
|
|
194
|
+
├── docs/
|
|
195
|
+
│ ├── phase3-spec.md # Phase 3 设计文档(CLI + Plugin)
|
|
196
|
+
│ ├── v1-roadmap.md # v1 功能路线图
|
|
197
|
+
│ └── v2-architecture.md # v2 多 Agent 架构设计
|
|
198
|
+
├── plugins/agentbridge/ # Claude Code 插件包
|
|
199
|
+
│ ├── .claude-plugin/plugin.json
|
|
200
|
+
│ ├── commands/init.md
|
|
201
|
+
│ ├── hooks/hooks.json
|
|
202
|
+
│ ├── scripts/health-check.sh
|
|
203
|
+
│ └── server/ # 打包的 bridge-server.js + daemon.js
|
|
204
|
+
├── src/
|
|
205
|
+
│ ├── bridge.ts # Claude 前台 MCP 客户端(插件入口)
|
|
206
|
+
│ ├── daemon.ts # 常驻后台 daemon
|
|
207
|
+
│ ├── daemon-client.ts # daemon 控制端口的 WebSocket 客户端
|
|
208
|
+
│ ├── daemon-lifecycle.ts # 共享 daemon 生命周期(ensureRunning、kill、启动锁)
|
|
209
|
+
│ ├── control-protocol.ts # 前后台控制协议类型
|
|
210
|
+
│ ├── claude-adapter.ts # Claude Code channel 的 MCP server 适配层
|
|
211
|
+
│ ├── codex-adapter.ts # Codex app-server WebSocket 代理与消息拦截
|
|
212
|
+
│ ├── config-service.ts # 项目配置(.agentbridge/)读写
|
|
213
|
+
│ ├── state-dir.ts # 平台感知的状态目录解析
|
|
214
|
+
│ ├── message-filter.ts # 智能消息过滤(标记、摘要缓冲)
|
|
215
|
+
│ ├── types.ts # 共享类型
|
|
216
|
+
│ ├── cli.ts # CLI 入口和命令路由
|
|
217
|
+
│ └── cli/
|
|
218
|
+
│ ├── init.ts # agentbridge init
|
|
219
|
+
│ ├── claude.ts # agentbridge claude
|
|
220
|
+
│ ├── codex.ts # agentbridge codex
|
|
221
|
+
│ ├── kill.ts # agentbridge kill
|
|
222
|
+
│ └── dev.ts # agentbridge dev
|
|
223
|
+
├── CLAUDE.md # AI Agent 项目规则
|
|
224
|
+
├── CODE_OF_CONDUCT.md
|
|
225
|
+
├── CONTRIBUTING.md
|
|
226
|
+
├── LICENSE
|
|
227
|
+
├── README.md
|
|
228
|
+
├── README.zh-CN.md
|
|
229
|
+
├── SECURITY.md
|
|
230
|
+
├── package.json
|
|
231
|
+
└── tsconfig.json
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## 配置
|
|
235
|
+
|
|
236
|
+
### 环境变量
|
|
237
|
+
|
|
238
|
+
| 变量 | 默认值 | 说明 |
|
|
239
|
+
|------|--------|------|
|
|
240
|
+
| `CODEX_WS_PORT` | `4500` | Codex app-server WebSocket 端口 |
|
|
241
|
+
| `CODEX_PROXY_PORT` | `4501` | Bridge 代理端口,Codex TUI 连接此端口 |
|
|
242
|
+
| `AGENTBRIDGE_CONTROL_PORT` | `4502` | bridge.ts 与 daemon.ts 之间的控制端口 |
|
|
243
|
+
| `AGENTBRIDGE_STATE_DIR` | 平台默认 | 状态目录(pid、status、日志)。macOS: `~/Library/Application Support/agentbridge/`,Linux: `$XDG_STATE_HOME/agentbridge/` |
|
|
244
|
+
| `AGENTBRIDGE_MODE` | `push` | 消息投递模式(`push` 用于 channel,`pull` 用于 API key 模式) |
|
|
245
|
+
| `AGENTBRIDGE_DAEMON_ENTRY` | `./daemon.ts` | 覆盖 daemon 入口(插件包使用) |
|
|
246
|
+
|
|
247
|
+
### 状态目录
|
|
248
|
+
|
|
249
|
+
daemon 在平台感知的目录中存储运行时状态:
|
|
250
|
+
|
|
251
|
+
| 平台 | 默认路径 |
|
|
252
|
+
|------|---------|
|
|
253
|
+
| macOS | `~/Library/Application Support/agentbridge/` |
|
|
254
|
+
| Linux | `$XDG_STATE_HOME/agentbridge/`(回退:`~/.local/state/agentbridge/`) |
|
|
255
|
+
|
|
256
|
+
内容:`daemon.pid`、`status.json`、`agentbridge.log`、`killed`(sentinel)、`startup.lock`
|
|
257
|
+
|
|
258
|
+
## 当前限制
|
|
259
|
+
|
|
260
|
+
- 目前只转发 `agentMessage`,不转发 `commandExecution`、`fileChange` 等中间过程事件
|
|
261
|
+
- 当前只支持单个 Codex thread,不支持多会话
|
|
262
|
+
- 当前只支持单个 Claude 前台连接;新的 Claude 会话会替换旧连接
|
|
263
|
+
- 固定端口意味着每台机器只能运行一个 AgentBridge 实例(多项目并行支持计划在 v1 之后)
|
|
264
|
+
|
|
265
|
+
### Codex 的 Git 操作限制
|
|
266
|
+
|
|
267
|
+
Codex 运行在沙箱环境中,**禁止对 `.git` 目录进行任何写操作**。这意味着 Codex 无法执行 `git commit`、`git push`、`git pull`、`git checkout -b`、`git merge` 等任何修改 Git 元数据的命令。尝试执行这些命令会导致 Codex 会话无限期挂起。
|
|
268
|
+
|
|
269
|
+
**建议做法:** 让 Claude Code 负责所有 Git 操作(创建分支、提交、推送、创建 PR)。Codex 专注于代码修改,通过 `agentMessage` 汇报完成的工作,由 Claude Code 负责 Git 工作流。
|
|
270
|
+
|
|
271
|
+
## Roadmap
|
|
272
|
+
|
|
273
|
+
- **v1.x(当前)**:在不改变架构的前提下优化单桥体验 -- 降噪、控回合、定角色。详见 [docs/v1-roadmap.md](docs/v1-roadmap.md)。
|
|
274
|
+
- **v2(规划中)**:引入多 Agent 基础设施 -- Room 作用域协作、稳定身份、正式控制协议、更强的恢复语义。详见 [docs/v2-architecture.md](docs/v2-architecture.md)。
|
|
275
|
+
- **v3+(远期)**:更智能的协作、更丰富的策略、跨 runtime 的高级编排。
|
|
276
|
+
|
|
277
|
+
## 这个项目是怎么建成的
|
|
278
|
+
|
|
279
|
+
这个项目由 **Claude Code**(Anthropic)和 **Codex**(OpenAI)通过 AgentBridge 本身进行实时双向通信,在人类开发者的指挥下协作完成。开发者负责分配任务、审查进度,并指挥两个 Agent 并行工作、互相 review。
|
|
280
|
+
|
|
281
|
+
换句话说,AgentBridge 就是它自己的 proof of concept:两个来自不同厂商的 AI Agent,通过实时连接,肩并肩地交付代码。
|
|
282
|
+
|
|
283
|
+
## 联系方式
|
|
284
|
+
|
|
285
|
+
这是我首次开源的项目!欢迎对多 Agent 协作、AI 工具链感兴趣的朋友来交流,一起做一些更好玩的事情。
|
|
286
|
+
|
|
287
|
+
- **Twitter/X**: [@raysonmeng](https://x.com/raysonmeng)
|
|
288
|
+
- **小红书**: [主页](https://www.xiaohongshu.com/user/profile/62a3709d0000000021028b7e)
|
|
289
|
+
- **微信**: 扫描下方二维码添加好友
|
|
290
|
+
|
|
291
|
+
<img src="assets/wechat-qr.jpg" alt="微信二维码" width="300" />
|