@mmmjk/context-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/CHANGELOG.md +11 -0
- package/LICENSE +21 -0
- package/README.md +275 -0
- package/README.zh-CN.md +275 -0
- package/dist/src/adapters/claude-code/index.js +2 -0
- package/dist/src/adapters/claude-code/ingest.js +142 -0
- package/dist/src/adapters/claude-code/render.js +95 -0
- package/dist/src/adapters/claude-code/tool-map.js +52 -0
- package/dist/src/adapters/codex/apply-patch-parser.js +61 -0
- package/dist/src/adapters/codex/apply-patch.js +163 -0
- package/dist/src/adapters/codex/index.js +3 -0
- package/dist/src/adapters/codex/ingest.js +167 -0
- package/dist/src/adapters/codex/manifest.js +21 -0
- package/dist/src/adapters/codex/paths.js +15 -0
- package/dist/src/adapters/codex/render.js +90 -0
- package/dist/src/adapters/codex/tool-map.js +16 -0
- package/dist/src/canonical/ids.js +44 -0
- package/dist/src/canonical/schema.js +28 -0
- package/dist/src/canonical/tools.js +21 -0
- package/dist/src/cli.js +442 -0
- package/dist/src/mcp-server.js +75 -0
- package/dist/src/pair-map.js +20 -0
- package/dist/src/session-index.js +369 -0
- package/dist/src/sync-state.js +34 -0
- package/dist/src/sync.js +174 -0
- package/dist/src/title-sync.js +67 -0
- package/dist/src/translator.js +24 -0
- package/dist/src/utils/jsonl.js +30 -0
- package/dist/src/utils/path.js +12 -0
- package/package.json +52 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
- Added Claude Code <-> Codex session translation.
|
|
6
|
+
- Added one-shot `copy` for independent target sessions.
|
|
7
|
+
- Added `list`, `inspect`, `smoke`, `sync`, `watch`, `clean`, `dedupe`, `install-hook`, and MCP server commands.
|
|
8
|
+
- Added loop prevention for generated sessions.
|
|
9
|
+
- Added dirty-target conflict protection for sync.
|
|
10
|
+
- Added prompt display cleanup for bootstrap and command-wrapper prompts.
|
|
11
|
+
- Added npm packaging configuration for the `context-bridge` CLI.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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,275 @@
|
|
|
1
|
+
# Context Bridge
|
|
2
|
+
|
|
3
|
+
**Language:** English | [简体中文](README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
Context Bridge is a local-first session interoperability layer for coding agents. It moves JSONL session history between Claude Code, Codex, and MCP-aware automation surfaces through a canonical intermediate representation, preserving enough operational context to resume work across harness boundaries.
|
|
6
|
+
|
|
7
|
+
It is designed for developers who use more than one CLI agent and need controlled session migration, one-shot duplication, local sync, and machine-readable session discovery without relying on a hosted service.
|
|
8
|
+
|
|
9
|
+
## Why It Exists
|
|
10
|
+
|
|
11
|
+
Modern coding agents store rich execution traces: user turns, assistant output, tool calls, file operations, shell commands, working directories, timestamps, and display titles. Those traces are valuable, but they are usually locked inside harness-specific JSONL formats.
|
|
12
|
+
|
|
13
|
+
Context Bridge provides a small translation boundary:
|
|
14
|
+
|
|
15
|
+
- **Canonical IR**: harness-specific events are normalized into a shared `Session` model.
|
|
16
|
+
- **Bidirectional adapters**: Claude Code and Codex each own their ingest/render logic.
|
|
17
|
+
- **Provenance-aware sync**: generated sessions are marked, tracked, deduped, and skipped as future sources.
|
|
18
|
+
- **Independent copy mode**: sessions can be duplicated into another agent without creating a sync relationship.
|
|
19
|
+
- **Local MCP surface**: external MCP hosts can list, translate, and prepare resume commands.
|
|
20
|
+
|
|
21
|
+
## Capabilities
|
|
22
|
+
|
|
23
|
+
| Capability | Description |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| Session translation | Convert Claude Code JSONL to Codex JSONL, and Codex JSONL to Claude Code JSONL. |
|
|
26
|
+
| Session copy | Create a fresh target-agent session with no tracking metadata. |
|
|
27
|
+
| Session index | List and inspect local sessions across harnesses with readable display prompts. |
|
|
28
|
+
| Batch sync | Scan recent original sessions and generate deterministic tracked targets. |
|
|
29
|
+
| Divergence protection | Skip tracked targets that were modified after generation unless `--force` is used. |
|
|
30
|
+
| Loop prevention | Prevent generated sessions from being re-translated into new generated chains. |
|
|
31
|
+
| Hook integration | Install Claude Code Stop hooks or Codex notify hooks for lightweight auto-sync. |
|
|
32
|
+
| MCP server | Expose session operations to MCP-aware hosts through stdio. |
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
Requirements:
|
|
37
|
+
|
|
38
|
+
- Node.js `>=20`
|
|
39
|
+
|
|
40
|
+
Install from this checkout:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install
|
|
44
|
+
npm run build
|
|
45
|
+
npm install -g .
|
|
46
|
+
context-bridge --help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Install from npm after publishing:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install -g @mmmjk/context-bridge
|
|
53
|
+
context-bridge --help
|
|
54
|
+
ctxb --help
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For local development without global installation:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
node dist/src/cli.js --help
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The primary binary name is `context-bridge`. A shorter alias, `ctxb`, is also installed.
|
|
64
|
+
|
|
65
|
+
## Quick Start
|
|
66
|
+
|
|
67
|
+
Find a session, verify conversion, then translate it:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
context-bridge list --harness both --days 30 -n 20
|
|
71
|
+
context-bridge inspect <session-id>
|
|
72
|
+
context-bridge smoke <session-id>
|
|
73
|
+
context-bridge translate <session-id>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The same commands can be run with the short alias:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
ctxb list --harness both --days 30 -n 20
|
|
80
|
+
ctxb translate <session-id>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Run the resume command printed by `translate`, then replace `<your prompt>`.
|
|
84
|
+
|
|
85
|
+
Create a one-shot independent duplicate instead:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
context-bridge copy <session-id>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Mental Model
|
|
92
|
+
|
|
93
|
+
There are three primary flows:
|
|
94
|
+
|
|
95
|
+
| Flow | Use when | Result |
|
|
96
|
+
| --- | --- | --- |
|
|
97
|
+
| `translate` | You want a generated migration artifact. | A target session with source metadata. |
|
|
98
|
+
| `copy` | You want an independent native-looking target session. | A fresh target session with no sync tracking. |
|
|
99
|
+
| `sync` / `watch` | You want recent original sessions mirrored automatically. | Deterministic tracked targets with fingerprint state. |
|
|
100
|
+
|
|
101
|
+
`translate` and `sync` are provenance-aware. Their outputs can be identified later, cleaned, deduped, and protected from chain translation.
|
|
102
|
+
|
|
103
|
+
`copy` is deliberately untracked. It uses the same canonical conversion pipeline, but omits `source_harness`, `originator: "context-bridge"`, `context-bridge-meta`, and `[from ...]` title prefixes.
|
|
104
|
+
|
|
105
|
+
## Command Reference
|
|
106
|
+
|
|
107
|
+
| Command | Purpose | Example |
|
|
108
|
+
| --- | --- | --- |
|
|
109
|
+
| `list` | List local sessions in a compact table. | `context-bridge list --harness both --days 7 -n 20` |
|
|
110
|
+
| `inspect` | Print one indexed session summary as JSON. | `context-bridge inspect <session-id>` |
|
|
111
|
+
| `smoke` | Verify translation and print the resume command without live model execution. | `context-bridge smoke <session-id>` |
|
|
112
|
+
| `translate` | Create a tracked generated session in the target harness. | `context-bridge translate <session-id>` |
|
|
113
|
+
| `copy` | Create an independent target session without sync tracking. | `context-bridge copy <session-id>` |
|
|
114
|
+
| `sync` | Batch-sync recent original sessions. | `context-bridge sync --direction both --days 365` |
|
|
115
|
+
| `watch` | Re-run sync on an interval, or once with `--once`. | `context-bridge watch --direction both --days 1 -i 30` |
|
|
116
|
+
| `clean` | Remove generated translated sessions. | `context-bridge clean --dry-run` |
|
|
117
|
+
| `dedupe` | Remove duplicate generated sessions. | `context-bridge dedupe --dry-run` |
|
|
118
|
+
| `install-hook` | Install automatic sync hooks. | `context-bridge install-hook --target codex` |
|
|
119
|
+
| `mcp serve` | Start the stdio MCP server. | `context-bridge mcp serve` |
|
|
120
|
+
| `mcp config-snippet` | Print an MCP host config snippet. | `context-bridge mcp config-snippet` |
|
|
121
|
+
|
|
122
|
+
Common options:
|
|
123
|
+
|
|
124
|
+
- `--from <claude-code|codex>` and `--to <claude-code|codex>` override inferred direction.
|
|
125
|
+
- `--target-dir <dir>` writes generated files to a custom target root.
|
|
126
|
+
- `--allow-generated` lets `translate` or `smoke` read a generated session.
|
|
127
|
+
- `--source <all|native|claude|codex>` filters `list` by origin.
|
|
128
|
+
- `--force` lets `sync` regenerate tracked targets.
|
|
129
|
+
- `--include-active` lets `sync` include the active Claude Code session.
|
|
130
|
+
|
|
131
|
+
## Workflows
|
|
132
|
+
|
|
133
|
+
### Move One Session
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
context-bridge list --harness both --days 14 -n 20
|
|
137
|
+
context-bridge smoke <session-id>
|
|
138
|
+
context-bridge translate <session-id>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
This creates a generated target session and prints the resume command. Use this when you want the migration to remain identifiable as a Context Bridge artifact.
|
|
142
|
+
|
|
143
|
+
### Copy Without Provenance
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
context-bridge copy <session-id>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This creates a new target session id every time. In `list` and `inspect`, the copied session appears native: `Source` is blank, `source_harness` is `null`, and cleanup commands will not treat it as generated.
|
|
150
|
+
|
|
151
|
+
### Sync Recent Sessions
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
context-bridge sync --direction both --days 365
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Directions:
|
|
158
|
+
|
|
159
|
+
- `both`
|
|
160
|
+
- `cc-to-codex`
|
|
161
|
+
- `codex-to-cc`
|
|
162
|
+
|
|
163
|
+
`sync` records source and target fingerprints under `~/.cache/context-bridge/`. If both source and target change after generation, the target is considered divergent and is skipped as a conflict.
|
|
164
|
+
|
|
165
|
+
### Install Lightweight Hooks
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
context-bridge install-hook --target claude-code
|
|
169
|
+
context-bridge install-hook --target codex
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Hooks are idempotent and marked with `context_bridge.cli sync`.
|
|
173
|
+
|
|
174
|
+
## Session Listing
|
|
175
|
+
|
|
176
|
+
`list` is optimized for scanning and selection:
|
|
177
|
+
|
|
178
|
+
- `Modified`: local timestamp in `yyyy-mm-dd hh:mm:ss`.
|
|
179
|
+
- `Harness`: current session store.
|
|
180
|
+
- `Source`: blank for native/copy sessions, `claude` or `codex` for generated sessions.
|
|
181
|
+
- `CWD`: working directory.
|
|
182
|
+
- `Display Prompt`: readable title or prompt with bootstrap noise filtered out.
|
|
183
|
+
|
|
184
|
+
`inspect` exposes raw machine-readable fields such as `first_prompt`, `display_prompt`, `session_title`, `source_harness`, `launch_context`, `start_command`, and `resume_command`.
|
|
185
|
+
|
|
186
|
+
## MCP Tools
|
|
187
|
+
|
|
188
|
+
Start the server:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
context-bridge mcp serve
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Available tools:
|
|
195
|
+
|
|
196
|
+
- `list_sessions`
|
|
197
|
+
- `translate_session`
|
|
198
|
+
- `sync_now`
|
|
199
|
+
- `find_session`
|
|
200
|
+
- `prepare_resume`
|
|
201
|
+
- `resume_with_prompt`
|
|
202
|
+
|
|
203
|
+
`resume_with_prompt` returns a command to run. It does not execute a live model process.
|
|
204
|
+
|
|
205
|
+
## Transfer Semantics
|
|
206
|
+
|
|
207
|
+
### Fully Transferable
|
|
208
|
+
|
|
209
|
+
| Data | Notes |
|
|
210
|
+
| --- | --- |
|
|
211
|
+
| User and assistant text | Plain text turns are preserved. |
|
|
212
|
+
| Shell commands | Common shell tool calls are mapped across harnesses. |
|
|
213
|
+
| File read/write/edit/delete/move | Claude Code file tools and Codex `apply_patch` are mapped to canonical file operations. |
|
|
214
|
+
| Search/glob operations | Common grep/glob patterns are preserved. |
|
|
215
|
+
| Tool results | Text output, call ids, and error flags are preserved when present. |
|
|
216
|
+
| Session title, cwd, timestamps, ids | Preserved or regenerated as target-native metadata. |
|
|
217
|
+
|
|
218
|
+
### Partially Transferable
|
|
219
|
+
|
|
220
|
+
| Data | Limitation |
|
|
221
|
+
| --- | --- |
|
|
222
|
+
| Tool calls without a target equivalent | Rendered conservatively instead of replayed as a native tool. |
|
|
223
|
+
| Web search and MCP calls | Preserved as canonical events; native behavior depends on target tool availability. |
|
|
224
|
+
| Attachments and developer notes | May render as JSON text or developer notes. |
|
|
225
|
+
| Reasoning summaries | Plain summaries can transfer; encrypted or signed payloads cannot. |
|
|
226
|
+
| Git, model, permissions, launch metadata | Captured when present; missing source fields cannot be reconstructed. Target sessions do not force a model override. |
|
|
227
|
+
| Subagent transcripts and compaction boundaries | Preserved as readable history or lossy markers, not as live runtime state. |
|
|
228
|
+
|
|
229
|
+
### Not Transferable
|
|
230
|
+
|
|
231
|
+
| Data | Examples |
|
|
232
|
+
| --- | --- |
|
|
233
|
+
| Encrypted or signed reasoning payloads | Hidden reasoning bodies, signatures, encrypted compaction content. |
|
|
234
|
+
| Exact original shell command used to launch the agent | Aliases, wrappers, env prefixes, complete argv. |
|
|
235
|
+
| Live model execution during transfer | `smoke` and MCP helpers prepare files/commands only. |
|
|
236
|
+
| Codex SQLite picker cache | JSONL and `session_index.jsonl` are written; SQLite cache is not mutated. |
|
|
237
|
+
| Native plan/task UI state | Stateful checklists and UI-only state are not reconstructed. |
|
|
238
|
+
| External service state | Browser sessions, cloud jobs, remote tool caches, credentials. |
|
|
239
|
+
| Unsupported harness formats | Any harness without an adapter. |
|
|
240
|
+
|
|
241
|
+
## Filesystem Layout
|
|
242
|
+
|
|
243
|
+
Target session stores:
|
|
244
|
+
|
|
245
|
+
- Claude Code: `~/.claude/projects/.../*.jsonl`
|
|
246
|
+
- Codex: `~/.codex/sessions/.../*.jsonl`
|
|
247
|
+
|
|
248
|
+
Codex title index:
|
|
249
|
+
|
|
250
|
+
- `~/.codex/session_index.jsonl`
|
|
251
|
+
|
|
252
|
+
Context Bridge sync state:
|
|
253
|
+
|
|
254
|
+
```text
|
|
255
|
+
~/.cache/context-bridge/
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Design Principles
|
|
259
|
+
|
|
260
|
+
- **Local-first**: no hosted control plane, no remote session upload.
|
|
261
|
+
- **Adapter isolation**: harness-specific parsing stays inside harness adapters.
|
|
262
|
+
- **Canonical-first translation**: all conversions pass through the shared `Session` model.
|
|
263
|
+
- **Conservative lossiness**: unsupported structures are represented explicitly instead of silently discarded.
|
|
264
|
+
- **Destructive safety**: cleanup only targets sessions that can be identified as generated.
|
|
265
|
+
- **Model neutrality**: target sessions do not force a source model; resumed agents use their current defaults.
|
|
266
|
+
|
|
267
|
+
## Development
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
npm run build
|
|
271
|
+
npm test
|
|
272
|
+
npm run pack:dry
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Release notes are in `CHANGELOG.md`. Publishing steps are in `docs/RELEASE.md`. Implementation details are in `docs/ARCHITECTURE.md`.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# Context Bridge
|
|
2
|
+
|
|
3
|
+
**语言:** [English](README.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
Context Bridge 是一个本地优先的编码代理会话互操作层。它通过统一的 canonical intermediate representation,在 Claude Code、Codex 和支持 MCP 的自动化工具之间迁移 JSONL 会话历史,并尽量保留跨 agent 恢复工作所需的操作上下文。
|
|
6
|
+
|
|
7
|
+
它适合同时使用多个 CLI agent 的开发者:你可以迁移 session、一次性复制 session、批量同步最近 session,也可以让 MCP host 用结构化工具读取和准备恢复命令。
|
|
8
|
+
|
|
9
|
+
## 为什么需要它
|
|
10
|
+
|
|
11
|
+
现代编码代理的 session 不只是聊天记录,还包含 user turn、assistant output、tool call、文件操作、shell 命令、工作目录、时间戳和标题等执行轨迹。但这些轨迹通常被锁在各自 harness 的 JSONL 格式里。
|
|
12
|
+
|
|
13
|
+
Context Bridge 提供一个轻量转换边界:
|
|
14
|
+
|
|
15
|
+
- **Canonical IR**:把不同 agent 的事件规范化成统一 `Session` 模型。
|
|
16
|
+
- **双向 adapter**:Claude Code 和 Codex 各自负责 ingest/render。
|
|
17
|
+
- **来源感知同步**:生成 session 可识别、可清理、可去重,并避免再次作为同步源。
|
|
18
|
+
- **独立复制模式**:可以复制到另一个 agent,但不建立后续同步关系。
|
|
19
|
+
- **本地 MCP surface**:让 MCP host 能列出 session、触发转换并准备恢复命令。
|
|
20
|
+
|
|
21
|
+
## 能力概览
|
|
22
|
+
|
|
23
|
+
| 能力 | 说明 |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| Session translation | Claude Code JSONL 与 Codex JSONL 双向转换。 |
|
|
26
|
+
| Session copy | 生成新的独立目标 session,不写追踪元数据。 |
|
|
27
|
+
| Session index | 跨 agent 列出和查看本地 session,并展示可读提示词。 |
|
|
28
|
+
| Batch sync | 扫描最近原生 session,生成确定性目标 session。 |
|
|
29
|
+
| Divergence protection | 目标 session 分叉后默认跳过,除非使用 `--force`。 |
|
|
30
|
+
| Loop prevention | 避免生成 session 再被同步成新的生成链。 |
|
|
31
|
+
| Hook integration | 安装 Claude Code Stop hook 或 Codex notify hook,轻量自动同步。 |
|
|
32
|
+
| MCP server | 通过 stdio 向 MCP host 暴露 session 工具。 |
|
|
33
|
+
|
|
34
|
+
## 安装
|
|
35
|
+
|
|
36
|
+
要求:
|
|
37
|
+
|
|
38
|
+
- Node.js `>=20`
|
|
39
|
+
|
|
40
|
+
从当前项目安装:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install
|
|
44
|
+
npm run build
|
|
45
|
+
npm install -g .
|
|
46
|
+
context-bridge --help
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
发布后从 npm 安装:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install -g @mmmjk/context-bridge
|
|
53
|
+
context-bridge --help
|
|
54
|
+
ctxb --help
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
本地开发可直接运行:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
node dist/src/cli.js --help
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
主命令名是 `context-bridge`,同时会安装更短的别名 `ctxb`。
|
|
64
|
+
|
|
65
|
+
## 快速开始
|
|
66
|
+
|
|
67
|
+
找到 session,验证转换,再正式迁移:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
context-bridge list --harness both --days 30 -n 20
|
|
71
|
+
context-bridge inspect <session-id>
|
|
72
|
+
context-bridge smoke <session-id>
|
|
73
|
+
context-bridge translate <session-id>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
同样可以使用短别名:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
ctxb list --harness both --days 30 -n 20
|
|
80
|
+
ctxb translate <session-id>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
执行 `translate` 输出的 resume 命令,并替换 `<your prompt>`。
|
|
84
|
+
|
|
85
|
+
如果只想一次性复制到另一个 agent:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
context-bridge copy <session-id>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 心智模型
|
|
92
|
+
|
|
93
|
+
核心有三条路径:
|
|
94
|
+
|
|
95
|
+
| 路径 | 适用场景 | 结果 |
|
|
96
|
+
| --- | --- | --- |
|
|
97
|
+
| `translate` | 需要生成可识别的迁移产物。 | 带来源元数据的目标 session。 |
|
|
98
|
+
| `copy` | 需要独立、原生观感的目标 session。 | 无同步追踪的新目标 session。 |
|
|
99
|
+
| `sync` / `watch` | 需要自动镜像最近原生 session。 | 带 fingerprint 状态的确定性目标 session。 |
|
|
100
|
+
|
|
101
|
+
`translate` 和 `sync` 是 provenance-aware 的:生成物后续可识别、可清理、可去重,并会被跳过以避免链式迁移。
|
|
102
|
+
|
|
103
|
+
`copy` 是刻意不追踪的:它复用同一套 canonical 转换管线,但不写 `source_harness`、`originator: "context-bridge"`、`context-bridge-meta` 和 `[from ...]` 标题前缀。
|
|
104
|
+
|
|
105
|
+
## 命令参考
|
|
106
|
+
|
|
107
|
+
| 命令 | 作用 | 示例 |
|
|
108
|
+
| --- | --- | --- |
|
|
109
|
+
| `list` | 用紧凑表格列出本地 session。 | `context-bridge list --harness both --days 7 -n 20` |
|
|
110
|
+
| `inspect` | 用 JSON 输出单个 session 摘要。 | `context-bridge inspect <session-id>` |
|
|
111
|
+
| `smoke` | 验证转换并输出恢复命令,不执行真实模型。 | `context-bridge smoke <session-id>` |
|
|
112
|
+
| `translate` | 在目标 harness 生成可追踪迁移 session。 | `context-bridge translate <session-id>` |
|
|
113
|
+
| `copy` | 生成无同步追踪的独立目标 session。 | `context-bridge copy <session-id>` |
|
|
114
|
+
| `sync` | 批量同步最近原生 session。 | `context-bridge sync --direction both --days 365` |
|
|
115
|
+
| `watch` | 按间隔重复同步,或用 `--once` 只跑一次。 | `context-bridge watch --direction both --days 1 -i 30` |
|
|
116
|
+
| `clean` | 删除生成的迁移 session。 | `context-bridge clean --dry-run` |
|
|
117
|
+
| `dedupe` | 删除重复的生成 session。 | `context-bridge dedupe --dry-run` |
|
|
118
|
+
| `install-hook` | 安装自动同步 hook。 | `context-bridge install-hook --target codex` |
|
|
119
|
+
| `mcp serve` | 启动 stdio MCP server。 | `context-bridge mcp serve` |
|
|
120
|
+
| `mcp config-snippet` | 输出 MCP host 配置片段。 | `context-bridge mcp config-snippet` |
|
|
121
|
+
|
|
122
|
+
常用参数:
|
|
123
|
+
|
|
124
|
+
- `--from <claude-code|codex>` 和 `--to <claude-code|codex>`:覆盖自动推断方向。
|
|
125
|
+
- `--target-dir <dir>`:指定目标写入目录。
|
|
126
|
+
- `--allow-generated`:允许 `translate` 或 `smoke` 读取生成 session。
|
|
127
|
+
- `--source <all|native|claude|codex>`:按来源筛选 `list`。
|
|
128
|
+
- `--force`:让 `sync` 重新生成被追踪目标。
|
|
129
|
+
- `--include-active`:让 `sync` 包含当前活跃 Claude Code session。
|
|
130
|
+
|
|
131
|
+
## 常见工作流
|
|
132
|
+
|
|
133
|
+
### 迁移单个 Session
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
context-bridge list --harness both --days 14 -n 20
|
|
137
|
+
context-bridge smoke <session-id>
|
|
138
|
+
context-bridge translate <session-id>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
这会生成一个目标 session,并输出恢复命令。适合希望迁移产物保持可识别、可清理、可同步的场景。
|
|
142
|
+
|
|
143
|
+
### 无来源复制
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
context-bridge copy <session-id>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
每次都会创建新的目标 session id。在 `list` 和 `inspect` 中,复制结果表现为原生 session:`Source` 为空,`source_harness` 为 `null`,清理命令不会把它当成生成物。
|
|
150
|
+
|
|
151
|
+
### 同步最近 Session
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
context-bridge sync --direction both --days 365
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
支持方向:
|
|
158
|
+
|
|
159
|
+
- `both`
|
|
160
|
+
- `cc-to-codex`
|
|
161
|
+
- `codex-to-cc`
|
|
162
|
+
|
|
163
|
+
`sync` 会在 `~/.cache/context-bridge/` 记录源和目标 fingerprint。如果源和目标之后都发生变化,目标会被视为分叉并跳过。
|
|
164
|
+
|
|
165
|
+
### 安装轻量 Hook
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
context-bridge install-hook --target claude-code
|
|
169
|
+
context-bridge install-hook --target codex
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Hook 是幂等的,并带有 `context_bridge.cli sync` 标记。
|
|
173
|
+
|
|
174
|
+
## 会话列表
|
|
175
|
+
|
|
176
|
+
`list` 用于快速扫描和选择:
|
|
177
|
+
|
|
178
|
+
- `Modified`:本地时区 `yyyy-mm-dd hh:mm:ss`。
|
|
179
|
+
- `Harness`:当前 session 所在 agent。
|
|
180
|
+
- `Source`:原生/copy session 为空;生成 session 显示 `claude` 或 `codex`。
|
|
181
|
+
- `CWD`:工作目录。
|
|
182
|
+
- `Display Prompt`:过滤启动噪声后的可读标题或提示词。
|
|
183
|
+
|
|
184
|
+
`inspect` 输出机器可读字段,包括 `first_prompt`、`display_prompt`、`session_title`、`source_harness`、`launch_context`、`start_command` 和 `resume_command`。
|
|
185
|
+
|
|
186
|
+
## MCP Tools
|
|
187
|
+
|
|
188
|
+
启动服务:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
context-bridge mcp serve
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
可用工具:
|
|
195
|
+
|
|
196
|
+
- `list_sessions`
|
|
197
|
+
- `translate_session`
|
|
198
|
+
- `sync_now`
|
|
199
|
+
- `find_session`
|
|
200
|
+
- `prepare_resume`
|
|
201
|
+
- `resume_with_prompt`
|
|
202
|
+
|
|
203
|
+
`resume_with_prompt` 只返回可执行命令,不启动真实模型进程。
|
|
204
|
+
|
|
205
|
+
## 转移语义
|
|
206
|
+
|
|
207
|
+
### 完全可转移
|
|
208
|
+
|
|
209
|
+
| 数据 | 说明 |
|
|
210
|
+
| --- | --- |
|
|
211
|
+
| 用户和助手文本 | 普通文本回合会保留。 |
|
|
212
|
+
| Shell 命令 | 常见 shell tool call 会跨 harness 映射。 |
|
|
213
|
+
| 文件读写编辑删除移动 | Claude Code 文件工具和 Codex `apply_patch` 会映射为统一文件操作。 |
|
|
214
|
+
| 搜索/glob 操作 | 常见 grep/glob 模式会保留。 |
|
|
215
|
+
| Tool 结果 | 文本输出、call id 和错误标记在存在时会保留。 |
|
|
216
|
+
| Session 标题、cwd、时间戳、id | 保留或重新生成为目标原生元数据。 |
|
|
217
|
+
|
|
218
|
+
### 部分可转移
|
|
219
|
+
|
|
220
|
+
| 数据 | 限制 |
|
|
221
|
+
| --- | --- |
|
|
222
|
+
| 目标 agent 没有等价能力的 tool call | 会保守渲染,不等价于原生 tool replay。 |
|
|
223
|
+
| Web search 和 MCP call | 会保留为 canonical event;目标原生行为取决于可用工具。 |
|
|
224
|
+
| 附件和 developer note | 可能渲染为 JSON 文本或 developer note。 |
|
|
225
|
+
| Reasoning summary | 明文 summary 可转移;加密或签名 payload 不可转移。 |
|
|
226
|
+
| Git、模型、权限、启动元数据 | 存在时会捕获;缺失字段无法重建。目标 session 不强制指定模型。 |
|
|
227
|
+
| Subagent transcript 和 compaction 边界 | 作为可读历史或有损标记保留,不恢复运行态。 |
|
|
228
|
+
|
|
229
|
+
### 不可转移
|
|
230
|
+
|
|
231
|
+
| 数据 | 例子 |
|
|
232
|
+
| --- | --- |
|
|
233
|
+
| 加密或签名 reasoning payload | 隐藏 reasoning、签名、加密 compaction 内容。 |
|
|
234
|
+
| 启动 agent 的完整原始 shell 命令 | alias、wrapper、环境变量前缀、完整 argv。 |
|
|
235
|
+
| 转换过程中的实时模型执行 | `smoke` 和 MCP helper 只准备文件/命令。 |
|
|
236
|
+
| Codex SQLite picker cache | 会写 JSONL 和 `session_index.jsonl`,不修改 SQLite cache。 |
|
|
237
|
+
| 原生 plan/task UI 状态 | 有状态 checklist 和 UI-only 状态不会重建。 |
|
|
238
|
+
| 外部服务状态 | 浏览器登录态、云端 job、远端 tool cache、凭证。 |
|
|
239
|
+
| 未支持的 harness 格式 | 没有 adapter 的任何 session 格式。 |
|
|
240
|
+
|
|
241
|
+
## 文件布局
|
|
242
|
+
|
|
243
|
+
目标 session 目录:
|
|
244
|
+
|
|
245
|
+
- Claude Code:`~/.claude/projects/.../*.jsonl`
|
|
246
|
+
- Codex:`~/.codex/sessions/.../*.jsonl`
|
|
247
|
+
|
|
248
|
+
Codex 标题索引:
|
|
249
|
+
|
|
250
|
+
- `~/.codex/session_index.jsonl`
|
|
251
|
+
|
|
252
|
+
Context Bridge 同步状态:
|
|
253
|
+
|
|
254
|
+
```text
|
|
255
|
+
~/.cache/context-bridge/
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## 设计原则
|
|
259
|
+
|
|
260
|
+
- **Local-first**:没有托管控制面,不上传远端 session。
|
|
261
|
+
- **Adapter isolation**:harness 特定解析逻辑只存在于对应 adapter。
|
|
262
|
+
- **Canonical-first translation**:所有转换都经过统一 `Session` 模型。
|
|
263
|
+
- **Conservative lossiness**:不支持的结构显式降级表示,而不是静默丢弃。
|
|
264
|
+
- **Destructive safety**:清理命令只处理可识别的生成 session。
|
|
265
|
+
- **Model neutrality**:目标 session 不强制沿用源模型,恢复时使用目标 agent 当前默认配置。
|
|
266
|
+
|
|
267
|
+
## 开发
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
npm run build
|
|
271
|
+
npm test
|
|
272
|
+
npm run pack:dry
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
发布记录见 `CHANGELOG.md`。发布步骤见 `docs/RELEASE.md`。实现细节见 `docs/ARCHITECTURE.md`。
|