session-tape 0.1.0__tar.gz

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.
Files changed (31) hide show
  1. session_tape-0.1.0/LICENSE +21 -0
  2. session_tape-0.1.0/PKG-INFO +203 -0
  3. session_tape-0.1.0/README.md +191 -0
  4. session_tape-0.1.0/pyproject.toml +24 -0
  5. session_tape-0.1.0/session_tape/__init__.py +13 -0
  6. session_tape-0.1.0/session_tape/__main__.py +3 -0
  7. session_tape-0.1.0/session_tape/_deps.py +51 -0
  8. session_tape-0.1.0/session_tape/cli.py +222 -0
  9. session_tape-0.1.0/session_tape/model.py +33 -0
  10. session_tape-0.1.0/session_tape/noise.py +83 -0
  11. session_tape-0.1.0/session_tape/render/__init__.py +34 -0
  12. session_tape-0.1.0/session_tape/render/claude.py +102 -0
  13. session_tape-0.1.0/session_tape/render/codex.py +247 -0
  14. session_tape-0.1.0/session_tape/render/hermes.py +101 -0
  15. session_tape-0.1.0/session_tape/render/openclaw.py +52 -0
  16. session_tape-0.1.0/session_tape/render/pi.py +75 -0
  17. session_tape-0.1.0/session_tape/render/workbuddy.py +127 -0
  18. session_tape-0.1.0/session_tape/source.py +93 -0
  19. session_tape-0.1.0/session_tape/ui.py +235 -0
  20. session_tape-0.1.0/session_tape.egg-info/PKG-INFO +203 -0
  21. session_tape-0.1.0/session_tape.egg-info/SOURCES.txt +29 -0
  22. session_tape-0.1.0/session_tape.egg-info/dependency_links.txt +1 -0
  23. session_tape-0.1.0/session_tape.egg-info/entry_points.txt +2 -0
  24. session_tape-0.1.0/session_tape.egg-info/requires.txt +3 -0
  25. session_tape-0.1.0/session_tape.egg-info/top_level.txt +1 -0
  26. session_tape-0.1.0/setup.cfg +4 -0
  27. session_tape-0.1.0/tests/test_codex_render.py +92 -0
  28. session_tape-0.1.0/tests/test_more_targets.py +106 -0
  29. session_tape-0.1.0/tests/test_noise.py +67 -0
  30. session_tape-0.1.0/tests/test_pi_render.py +85 -0
  31. session_tape-0.1.0/tests/test_workbuddy_render.py +61 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OfferKuai (Offer快) Team
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.
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.4
2
+ Name: session-tape
3
+ Version: 0.1.0
4
+ Summary: 把一个产品的会话历史搬到另一个产品里继续(只搬文本历史,单向)
5
+ License: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Provides-Extra: source
10
+ Requires-Dist: session-fork-core; extra == "source"
11
+ Dynamic: license-file
12
+
13
+ # session-tape
14
+
15
+ **中文** | [English](README.en.md)
16
+
17
+ [![CI](https://github.com/yamingmou/session-tape/actions/workflows/ci.yml/badge.svg)](https://github.com/yamingmou/session-tape/actions/workflows/ci.yml)
18
+ [![tag](https://img.shields.io/github/v/tag/yamingmou/session-tape?sort=semver)](https://github.com/yamingmou/session-tape/tags)
19
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
20
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](pyproject.toml)
21
+ [![Runtime deps](https://img.shields.io/badge/runtime%20deps-0-brightgreen.svg)](pyproject.toml)
22
+
23
+ **把一个产品的会话历史,搬到另一个产品里继续。**
24
+
25
+ 只搬**人说的话和模型的回答**——也就是历史。工具调用、附件、思考过程、模型身份都不搬:这些每家产品都不一样,搬过去也没有对应物,硬凑只会让新会话变得不可信。
26
+
27
+ 搬过去之后,历史是**真历史**:目标产品把它当自己的会话打开,往下按它自己的方式跑。
28
+
29
+ ![session-tape demo](docs/demo.svg)
30
+
31
+ *上图是 `session-tape demo` 的真实输出(读完 4 条消息,按 6 种产品的格式各写一份)。*
32
+
33
+ ---
34
+
35
+ ## 一分钟看懂
36
+
37
+ ```
38
+ 读 A 的历史 → 规范成 (角色, 文本, 时间) → 按 B 的格式写出来 → 用 B 自己验收
39
+ ```
40
+
41
+ 关键在最后一步:**验收一律用目标产品自己**——它自己的解析器能不能读、列表里能不能出现、能不能接着聊。不用我们自己的断言自证。
42
+
43
+ ## 它不是"打分支"
44
+
45
+ | | 做什么 | 用哪个 |
46
+ |---|---|---|
47
+ | **打分支** | **同一个产品内**复制一段前缀,保留工具调用与全部结构 | [`session-fork`](https://github.com/yamingmou/session-fork-core) |
48
+ | **会话迁移**(本项目) | **跨产品**搬运历史,只保留对话文本 | session-tape |
49
+
50
+ 两者共用一套**读产品会话的适配器层**——那是 `session-fork` 的核心资产(六个产品逐个真机验过)。本项目**不复制**那份代码,直接把它当依赖:读到的东西一样,做的事完全不同。
51
+
52
+ > 如果你要的是"在同一个产品里从某个点重开",用 `session-fork`;
53
+ > 如果你要的是"把我的历史换个产品继续",用这里。
54
+
55
+ ## 与同类项目的关系
56
+
57
+ 同一件事还有别的做法,说清差异比说"我们更好"有用:
58
+
59
+ | | session-tape | 覆盖面更广的同类工具 |
60
+ |---|---|---|
61
+ | **做法** | 薄中间层:只归一化 `(角色, 文本, 时间)`,其余不碰 | 厚中间层:工具调用、思考、压缩边界都建模,再映射到各产品 |
62
+ | **产品覆盖** | 6 个(含 WorkBuddy、OpenClaw) | 十几个到二十个不等 |
63
+ | **落地方式** | 能"官方建壳"就官方建壳(如 Codex 的 `--fill`),我们只灌内容 | 自己造容器 + 自己登记 |
64
+ | **验收** | 一律用目标产品自己读 / 列 / 续跑 | 各家不同 |
65
+
66
+ 我们**不打算**在产品数量上追平:这个项目的定位是**跨平台机制本身**,先把"搬过去真的能用"这件事做透。薄的好处是丢什么你一眼能看见;厚的好处是覆盖更多细节——两条路都成立,我们走前者。
67
+
68
+ ## 支持矩阵
69
+
70
+ **读**(源)与**写**(目标)各自独立,任意组合都成立——所以是 N + M 条适配器,不是 N × M 条转换器。
71
+
72
+ | | pi | codex | WorkBuddy | Claude Code | Hermes | OpenClaw |
73
+ |---|---|---|---|---|---|---|
74
+ | **读**(作为源) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
75
+ | **写**(作为目标) | ✅ L3 | ✅ L3 | ✅ L2 | ✅ L1 | ✅ L2 | ✅ L1 |
76
+
77
+ **验收等级**(混着写就是自欺,所以分级标注):
78
+
79
+ | 等级 | 含义 |
80
+ |---|---|
81
+ | **L3** | 目标产品自己读下来 **+ 真的续跑一轮**(不只是"文件看起来对") |
82
+ | **L2** | 写进产品的真实库/目录副本,用**产品自己的读法**读回,内容一致 |
83
+ | **L1** | 只有格式往返(用我们镜像产品格式的读器读回);本机没装那个产品,未做真机 |
84
+
85
+ 已跑通的组合(2026-11-24):WorkBuddy→pi、WorkBuddy→codex、WorkBuddy→WorkBuddy(换目录)、Codex→pi、Codex→codex、Codex→WorkBuddy、pi→codex,以及**链式** WorkBuddy→pi→codex(29 → 29 → 29 条,时间保留源的真实日期)。
86
+
87
+ 逐条证据与自验命令见 [`验收单.md`](验收单.md)。
88
+
89
+ ## 60 秒上手
90
+
91
+ ### 装(三选一)
92
+
93
+ ```sh
94
+ # ① 一行装(自动挑 uv / pipx / pip,装在独立环境里)
95
+ curl -fsSL https://raw.githubusercontent.com/yamingmou/session-tape/main/install.sh | sh
96
+
97
+ # ② 自己用包管理器
98
+ uv tool install "git+https://github.com/yamingmou/session-tape.git" # 或 pipx install
99
+ pip install --user "git+https://github.com/yamingmou/session-tape.git"
100
+
101
+ # ③ 不装,克隆下来直接跑(零依赖,Python 3.10+)
102
+ git clone https://github.com/yamingmou/session-tape && cd session-tape
103
+ python3 -m session_tape --help
104
+ ```
105
+
106
+ > 只是想看看效果?`session-tape demo` —— 不需要装任何产品,也不需要你的真实会话。
107
+
108
+ ### 用(从简单到精确)
109
+
110
+ ```sh
111
+ session-tape demo # ① 看效果:造 4 条消息,渲染成 6 种产品的格式,打印产物
112
+ session-tape list # ② 看有什么:列出本机各产品的会话,带编号
113
+ session-tape # ③ 向导:问你从哪搬到哪,替你拼好参数
114
+ ```
115
+
116
+ 向导会走这几步:选源产品 → 从列表里挑会话 → 选目标 → (目标需要的话)确认落地位置 → 预览要执行的命令 → 确认。**不需要记任何 id,也不需要背参数。**
117
+
118
+ 大会话(几 MB 以上)会提醒你可以只搬最后几轮:
119
+
120
+ ```sh
121
+ session-tape --from workbuddy --session <id> --to pi --out <目录> --limit 20
122
+ ```
123
+
124
+ ### 精确用法(向导只是替你拼这些)
125
+
126
+ ```sh
127
+ # 搬到 pi(文件型:造头部 + 线性 id 链)
128
+ session-tape --from workbuddy --session <会话id> --to pi --out <pi 的 sessions 目录>
129
+
130
+ # 搬到 codex —— 推荐「官方建壳 + 灌内容」:
131
+ # 先在 Codex 界面上 fork 一条,拿到它的 id,再把历史灌进去
132
+ session-tape --from workbuddy --session <id> --to codex \
133
+ --fill <界面 fork 出来的 id> --name "标题"
134
+
135
+ # 搬到 codex —— 自己造壳 + 登记(没有官方壳时)
136
+ session-tape --from codex --session-file <某 rollout> --to codex \
137
+ --install-codex-home ~/.codex --name "标题"
138
+
139
+ # 搬到 WorkBuddy(建议先指到库副本,确认无误再写真实库)
140
+ session-tape --from codex --session-file <某 rollout> --to workbuddy \
141
+ --install-wb-home <含 workbuddy.db 与 projects/ 的目录> --name "标题" --cwd <真实目录>
142
+
143
+ # 搬到 Claude Code / Hermes / OpenClaw
144
+ session-tape --from workbuddy --session <id> --to claude-code --out ~/.claude
145
+ session-tape --from workbuddy --session <id> --to hermes --out ~/.hermes/state.db
146
+ session-tape --from workbuddy --session <id> --to openclaw --out ~/.openclaw
147
+ ```
148
+
149
+ 通用开关:`--session-file`(源 id 有歧义时直接指文件)、`--limit N`(只搬最后几轮,落在轮边界上)、`--dry-run`(只统计不落盘)。
150
+
151
+ ### 自己验
152
+
153
+ ```sh
154
+ python3 scripts/selfcheck.py # 一条命令跑完全部检查,打印表格;退出码 0 = 全过
155
+
156
+ # pi 的真机门禁:空 HOME + 本地协议桩 + 假 key,断言「历史真的进了上下文」
157
+ python3 scripts/verify_gate_pi.py --pi <pi 可执行文件> --session <迁移产物>
158
+ ```
159
+
160
+ ## 每个新目标必须回答三件事
161
+
162
+ 矩阵不会自己变绿。加一个目标产品,必须能把这三问答完:
163
+
164
+ 1. **容器怎么来** —— 文件型自己造头部;库型拿产品自己建的一条当模板;能"官方建壳"的优先用官方(codex 的 `--fill` 就是这么来的);
165
+ 2. **怎么让产品看见** —— 只写文件不够:库型产品要补登记一行,否则文件在、列表里没有;
166
+ 3. **怎么验** —— 用产品自己的解析器 / 列表 / 续跑。我们自己的断言不算。
167
+
168
+ ## 它不做什么
169
+
170
+ 1. **不搬实现**:工具调用、附件、思考过程、工作区文件都不搬。所以历史"读得通、能接着聊",但**别指望它在 B 里重放当初的工具动作**。
171
+ 2. **单向**:A → B。在 B 里继续之后想回 A,那是再做一次迁移。
172
+ 3. **不改源**:读源产品时只读,不动任何文件。
173
+ 4. **不替你决定模型**:目标会话按目标产品自己的模型配置跑。
174
+
175
+ ## 目录
176
+
177
+ ```
178
+ session_tape/
179
+ source.py 读源(调 session-fork-core 的适配器)→ 规范化成 Msg
180
+ noise.py 丢掉占位/中断文本、合并重复投递
181
+ render/ 每个目标一个写入器:pi / codex / workbuddy / claude / hermes / openclaw
182
+ cli.py 命令行
183
+ scripts/
184
+ verify_gate_pi.py 真机门禁(协议桩)
185
+ selfcheck.py 一键自检
186
+ tests/ 契约测试与往返测试
187
+ reference/ 上游项目的格式与验收文档(MIT,注明出处)
188
+ lab/ 最早的转换原型,留作对照
189
+ ```
190
+
191
+ ## 路线图
192
+
193
+ | 阶段 | 内容 | 状态 |
194
+ |---|---|---|
195
+ | P0 | 枢纽结构 + 首个写入器(pi) | ✅ |
196
+ | P1 | 六个目标写入器(本仓库已有读器的全部产品) | ✅ |
197
+ | P2 | **扩产品覆盖**:新产品 = 读器 + 写器 + 契约测试(候选:opencode、cursor、kimi、qwen、gemini、cline、kilo) | 🚧 下一步 |
198
+ | P3 | 同产品跨机:路径与账号字段的改写 | 待做 |
199
+ | P4 | 兜底:目标不在支持表内时,退化为「把上下文压成一条可粘贴的消息」 | 待做 |
200
+
201
+ ## 许可
202
+
203
+ MIT。`reference/` 下的第三方文档各自保留其许可证与出处。
@@ -0,0 +1,191 @@
1
+ # session-tape
2
+
3
+ **中文** | [English](README.en.md)
4
+
5
+ [![CI](https://github.com/yamingmou/session-tape/actions/workflows/ci.yml/badge.svg)](https://github.com/yamingmou/session-tape/actions/workflows/ci.yml)
6
+ [![tag](https://img.shields.io/github/v/tag/yamingmou/session-tape?sort=semver)](https://github.com/yamingmou/session-tape/tags)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](pyproject.toml)
9
+ [![Runtime deps](https://img.shields.io/badge/runtime%20deps-0-brightgreen.svg)](pyproject.toml)
10
+
11
+ **把一个产品的会话历史,搬到另一个产品里继续。**
12
+
13
+ 只搬**人说的话和模型的回答**——也就是历史。工具调用、附件、思考过程、模型身份都不搬:这些每家产品都不一样,搬过去也没有对应物,硬凑只会让新会话变得不可信。
14
+
15
+ 搬过去之后,历史是**真历史**:目标产品把它当自己的会话打开,往下按它自己的方式跑。
16
+
17
+ ![session-tape demo](docs/demo.svg)
18
+
19
+ *上图是 `session-tape demo` 的真实输出(读完 4 条消息,按 6 种产品的格式各写一份)。*
20
+
21
+ ---
22
+
23
+ ## 一分钟看懂
24
+
25
+ ```
26
+ 读 A 的历史 → 规范成 (角色, 文本, 时间) → 按 B 的格式写出来 → 用 B 自己验收
27
+ ```
28
+
29
+ 关键在最后一步:**验收一律用目标产品自己**——它自己的解析器能不能读、列表里能不能出现、能不能接着聊。不用我们自己的断言自证。
30
+
31
+ ## 它不是"打分支"
32
+
33
+ | | 做什么 | 用哪个 |
34
+ |---|---|---|
35
+ | **打分支** | **同一个产品内**复制一段前缀,保留工具调用与全部结构 | [`session-fork`](https://github.com/yamingmou/session-fork-core) |
36
+ | **会话迁移**(本项目) | **跨产品**搬运历史,只保留对话文本 | session-tape |
37
+
38
+ 两者共用一套**读产品会话的适配器层**——那是 `session-fork` 的核心资产(六个产品逐个真机验过)。本项目**不复制**那份代码,直接把它当依赖:读到的东西一样,做的事完全不同。
39
+
40
+ > 如果你要的是"在同一个产品里从某个点重开",用 `session-fork`;
41
+ > 如果你要的是"把我的历史换个产品继续",用这里。
42
+
43
+ ## 与同类项目的关系
44
+
45
+ 同一件事还有别的做法,说清差异比说"我们更好"有用:
46
+
47
+ | | session-tape | 覆盖面更广的同类工具 |
48
+ |---|---|---|
49
+ | **做法** | 薄中间层:只归一化 `(角色, 文本, 时间)`,其余不碰 | 厚中间层:工具调用、思考、压缩边界都建模,再映射到各产品 |
50
+ | **产品覆盖** | 6 个(含 WorkBuddy、OpenClaw) | 十几个到二十个不等 |
51
+ | **落地方式** | 能"官方建壳"就官方建壳(如 Codex 的 `--fill`),我们只灌内容 | 自己造容器 + 自己登记 |
52
+ | **验收** | 一律用目标产品自己读 / 列 / 续跑 | 各家不同 |
53
+
54
+ 我们**不打算**在产品数量上追平:这个项目的定位是**跨平台机制本身**,先把"搬过去真的能用"这件事做透。薄的好处是丢什么你一眼能看见;厚的好处是覆盖更多细节——两条路都成立,我们走前者。
55
+
56
+ ## 支持矩阵
57
+
58
+ **读**(源)与**写**(目标)各自独立,任意组合都成立——所以是 N + M 条适配器,不是 N × M 条转换器。
59
+
60
+ | | pi | codex | WorkBuddy | Claude Code | Hermes | OpenClaw |
61
+ |---|---|---|---|---|---|---|
62
+ | **读**(作为源) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
63
+ | **写**(作为目标) | ✅ L3 | ✅ L3 | ✅ L2 | ✅ L1 | ✅ L2 | ✅ L1 |
64
+
65
+ **验收等级**(混着写就是自欺,所以分级标注):
66
+
67
+ | 等级 | 含义 |
68
+ |---|---|
69
+ | **L3** | 目标产品自己读下来 **+ 真的续跑一轮**(不只是"文件看起来对") |
70
+ | **L2** | 写进产品的真实库/目录副本,用**产品自己的读法**读回,内容一致 |
71
+ | **L1** | 只有格式往返(用我们镜像产品格式的读器读回);本机没装那个产品,未做真机 |
72
+
73
+ 已跑通的组合(2026-11-24):WorkBuddy→pi、WorkBuddy→codex、WorkBuddy→WorkBuddy(换目录)、Codex→pi、Codex→codex、Codex→WorkBuddy、pi→codex,以及**链式** WorkBuddy→pi→codex(29 → 29 → 29 条,时间保留源的真实日期)。
74
+
75
+ 逐条证据与自验命令见 [`验收单.md`](验收单.md)。
76
+
77
+ ## 60 秒上手
78
+
79
+ ### 装(三选一)
80
+
81
+ ```sh
82
+ # ① 一行装(自动挑 uv / pipx / pip,装在独立环境里)
83
+ curl -fsSL https://raw.githubusercontent.com/yamingmou/session-tape/main/install.sh | sh
84
+
85
+ # ② 自己用包管理器
86
+ uv tool install "git+https://github.com/yamingmou/session-tape.git" # 或 pipx install
87
+ pip install --user "git+https://github.com/yamingmou/session-tape.git"
88
+
89
+ # ③ 不装,克隆下来直接跑(零依赖,Python 3.10+)
90
+ git clone https://github.com/yamingmou/session-tape && cd session-tape
91
+ python3 -m session_tape --help
92
+ ```
93
+
94
+ > 只是想看看效果?`session-tape demo` —— 不需要装任何产品,也不需要你的真实会话。
95
+
96
+ ### 用(从简单到精确)
97
+
98
+ ```sh
99
+ session-tape demo # ① 看效果:造 4 条消息,渲染成 6 种产品的格式,打印产物
100
+ session-tape list # ② 看有什么:列出本机各产品的会话,带编号
101
+ session-tape # ③ 向导:问你从哪搬到哪,替你拼好参数
102
+ ```
103
+
104
+ 向导会走这几步:选源产品 → 从列表里挑会话 → 选目标 → (目标需要的话)确认落地位置 → 预览要执行的命令 → 确认。**不需要记任何 id,也不需要背参数。**
105
+
106
+ 大会话(几 MB 以上)会提醒你可以只搬最后几轮:
107
+
108
+ ```sh
109
+ session-tape --from workbuddy --session <id> --to pi --out <目录> --limit 20
110
+ ```
111
+
112
+ ### 精确用法(向导只是替你拼这些)
113
+
114
+ ```sh
115
+ # 搬到 pi(文件型:造头部 + 线性 id 链)
116
+ session-tape --from workbuddy --session <会话id> --to pi --out <pi 的 sessions 目录>
117
+
118
+ # 搬到 codex —— 推荐「官方建壳 + 灌内容」:
119
+ # 先在 Codex 界面上 fork 一条,拿到它的 id,再把历史灌进去
120
+ session-tape --from workbuddy --session <id> --to codex \
121
+ --fill <界面 fork 出来的 id> --name "标题"
122
+
123
+ # 搬到 codex —— 自己造壳 + 登记(没有官方壳时)
124
+ session-tape --from codex --session-file <某 rollout> --to codex \
125
+ --install-codex-home ~/.codex --name "标题"
126
+
127
+ # 搬到 WorkBuddy(建议先指到库副本,确认无误再写真实库)
128
+ session-tape --from codex --session-file <某 rollout> --to workbuddy \
129
+ --install-wb-home <含 workbuddy.db 与 projects/ 的目录> --name "标题" --cwd <真实目录>
130
+
131
+ # 搬到 Claude Code / Hermes / OpenClaw
132
+ session-tape --from workbuddy --session <id> --to claude-code --out ~/.claude
133
+ session-tape --from workbuddy --session <id> --to hermes --out ~/.hermes/state.db
134
+ session-tape --from workbuddy --session <id> --to openclaw --out ~/.openclaw
135
+ ```
136
+
137
+ 通用开关:`--session-file`(源 id 有歧义时直接指文件)、`--limit N`(只搬最后几轮,落在轮边界上)、`--dry-run`(只统计不落盘)。
138
+
139
+ ### 自己验
140
+
141
+ ```sh
142
+ python3 scripts/selfcheck.py # 一条命令跑完全部检查,打印表格;退出码 0 = 全过
143
+
144
+ # pi 的真机门禁:空 HOME + 本地协议桩 + 假 key,断言「历史真的进了上下文」
145
+ python3 scripts/verify_gate_pi.py --pi <pi 可执行文件> --session <迁移产物>
146
+ ```
147
+
148
+ ## 每个新目标必须回答三件事
149
+
150
+ 矩阵不会自己变绿。加一个目标产品,必须能把这三问答完:
151
+
152
+ 1. **容器怎么来** —— 文件型自己造头部;库型拿产品自己建的一条当模板;能"官方建壳"的优先用官方(codex 的 `--fill` 就是这么来的);
153
+ 2. **怎么让产品看见** —— 只写文件不够:库型产品要补登记一行,否则文件在、列表里没有;
154
+ 3. **怎么验** —— 用产品自己的解析器 / 列表 / 续跑。我们自己的断言不算。
155
+
156
+ ## 它不做什么
157
+
158
+ 1. **不搬实现**:工具调用、附件、思考过程、工作区文件都不搬。所以历史"读得通、能接着聊",但**别指望它在 B 里重放当初的工具动作**。
159
+ 2. **单向**:A → B。在 B 里继续之后想回 A,那是再做一次迁移。
160
+ 3. **不改源**:读源产品时只读,不动任何文件。
161
+ 4. **不替你决定模型**:目标会话按目标产品自己的模型配置跑。
162
+
163
+ ## 目录
164
+
165
+ ```
166
+ session_tape/
167
+ source.py 读源(调 session-fork-core 的适配器)→ 规范化成 Msg
168
+ noise.py 丢掉占位/中断文本、合并重复投递
169
+ render/ 每个目标一个写入器:pi / codex / workbuddy / claude / hermes / openclaw
170
+ cli.py 命令行
171
+ scripts/
172
+ verify_gate_pi.py 真机门禁(协议桩)
173
+ selfcheck.py 一键自检
174
+ tests/ 契约测试与往返测试
175
+ reference/ 上游项目的格式与验收文档(MIT,注明出处)
176
+ lab/ 最早的转换原型,留作对照
177
+ ```
178
+
179
+ ## 路线图
180
+
181
+ | 阶段 | 内容 | 状态 |
182
+ |---|---|---|
183
+ | P0 | 枢纽结构 + 首个写入器(pi) | ✅ |
184
+ | P1 | 六个目标写入器(本仓库已有读器的全部产品) | ✅ |
185
+ | P2 | **扩产品覆盖**:新产品 = 读器 + 写器 + 契约测试(候选:opencode、cursor、kimi、qwen、gemini、cline、kilo) | 🚧 下一步 |
186
+ | P3 | 同产品跨机:路径与账号字段的改写 | 待做 |
187
+ | P4 | 兜底:目标不在支持表内时,退化为「把上下文压成一条可粘贴的消息」 | 待做 |
188
+
189
+ ## 许可
190
+
191
+ MIT。`reference/` 下的第三方文档各自保留其许可证与出处。
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "session-tape"
7
+ version = "0.1.0"
8
+ description = "把一个产品的会话历史搬到另一个产品里继续(只搬文本历史,单向)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "MIT" }
12
+ # 刻意零第三方运行时依赖:读侧复用 session-fork-core(可选依赖),
13
+ # 生成目标是纯标准库拼 JSON;技能若走 zip 分发也不吃亏。
14
+ dependencies = []
15
+
16
+ [project.optional-dependencies]
17
+ # 读源产品需要它(六个适配器都在里面)。不装也能用:--from 传一个 JSONL 目录时不需要。
18
+ source = ["session-fork-core"]
19
+
20
+ [project.scripts]
21
+ session-tape = "session_tape.cli:main"
22
+
23
+ [tool.setuptools.packages.find]
24
+ include = ["session_tape*"]
@@ -0,0 +1,13 @@
1
+ """迁移录音机:把 A 的历史搬进 B。
2
+
3
+ 三个概念要分清(混起来就会写出"跨产品打分支"这种不存在的东西):
4
+
5
+ - **读**:从源产品读出历史 → 规范化成 `Msg`(只有角色、文本、时间);
6
+ - **渲染**:把 `Msg` 序列按目标产品的格式写出来(每个目标一个 renderer);
7
+ - **验收**:一律用**目标产品自己**的解析器/列表/续跑,不用我们自己的断言自证。
8
+
9
+ 源产品的读取复用 `session-fork-core` 的适配器(六个产品都是真机验过的),
10
+ 本包不重复实现读取,也不复制它的代码。
11
+ """
12
+
13
+ __version__ = "0.1.0"
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())
@@ -0,0 +1,51 @@
1
+ """依赖兜底:`session-fork-core` 是读侧与部分写侧的依赖。
2
+
3
+ 两种到场方式都要支持:
4
+ · 已 `pip install`(正常安装路径);
5
+ · 开发期用环境变量 `FORK_CORE_PATH` 指向本地检出(不必先装)。
6
+
7
+ 统一在这里处理,避免每个模块各写一遍 `sys.path` 操作——那样一旦漏一处,
8
+ 表现是"某个目标突然说找不到模块",很难查。
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import os
13
+ import sys
14
+
15
+
16
+ class MissingDependency(SystemExit):
17
+ """缺依赖时抛这个:带可执行的修复指令,而不是一段栈回溯。"""
18
+
19
+ def __init__(self) -> None:
20
+ super().__init__(
21
+ "✗ 需要 session-fork-core(读产品会话的适配器层):\n"
22
+ ' pip install "git+https://github.com/yamingmou/session-fork-core.git"\n'
23
+ " 或设置 FORK_CORE_PATH=<本地检出路径> 后再跑"
24
+ )
25
+
26
+
27
+ def ensure_fork_core():
28
+ """返回 `fork_core` 模块;拿不到就抛 MissingDependency。"""
29
+ try:
30
+ import fork_core
31
+ return fork_core
32
+ except ImportError:
33
+ pass
34
+ path = os.environ.get("FORK_CORE_PATH")
35
+ if path and os.path.isdir(path):
36
+ if path not in sys.path:
37
+ sys.path.insert(0, path)
38
+ try:
39
+ import fork_core
40
+ return fork_core
41
+ except ImportError:
42
+ pass
43
+ raise MissingDependency()
44
+
45
+
46
+ def has_fork_core() -> bool:
47
+ try:
48
+ ensure_fork_core()
49
+ return True
50
+ except SystemExit:
51
+ return False