throughline 0.3.24 → 0.4.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.
Files changed (116) hide show
  1. package/.claude/commands/tl.md +6 -21
  2. package/.codex-sidecar.yml +62 -0
  3. package/CHANGELOG.md +632 -0
  4. package/README.ja.md +71 -46
  5. package/README.md +420 -76
  6. package/bin/throughline.mjs +169 -7
  7. package/codex/skills/throughline/SKILL.md +157 -0
  8. package/codex/skills/throughline/agents/openai.yaml +7 -0
  9. package/docs/INHERITANCE_ON_CLEAR_ONLY.md +159 -0
  10. package/docs/L1_L2_L3_REDESIGN.md +415 -0
  11. package/docs/PUBLIC_RELEASE_PLAN.md +185 -0
  12. package/docs/THROUGHLINE_CLEAR_AUTO_HANDOFF_PLAN.md +286 -0
  13. package/docs/THROUGHLINE_CODEX_DUAL_SUPPORT.md +249 -0
  14. package/docs/THROUGHLINE_CODEX_FIRST_ROADMAP.md +555 -0
  15. package/docs/THROUGHLINE_CODEX_MONITOR_IMPLEMENTATION_PLAN.md +220 -0
  16. package/docs/THROUGHLINE_CODEX_TRIM_IMPLEMENTATION_PLAN.md +528 -0
  17. package/docs/THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md +672 -0
  18. package/docs/archive/CONCEPT.md +476 -0
  19. package/docs/archive/EXPERIMENT.md +371 -0
  20. package/docs/archive/README.md +22 -0
  21. package/docs/archive/SESSION_LINKING_DESIGN.md +231 -0
  22. package/docs/archive/THROUGHLINE_NEXT_STEPS.md +134 -0
  23. package/docs/throughline-codex-trim-rollback-incident-report.md +306 -0
  24. package/docs/throughline-handoff-context.example.json +57 -0
  25. package/docs/throughline-rollback-context-trim-insight.md +455 -0
  26. package/package.json +6 -2
  27. package/src/baton.mjs +17 -45
  28. package/src/baton.test.mjs +4 -41
  29. package/src/cli/codex-capture.mjs +95 -0
  30. package/src/cli/codex-handoff-model-smoke.mjs +292 -0
  31. package/src/cli/codex-handoff-model-smoke.test.mjs +262 -0
  32. package/src/cli/codex-handoff-smoke.mjs +163 -0
  33. package/src/cli/codex-handoff-smoke.test.mjs +149 -0
  34. package/src/cli/codex-handoff-start.mjs +291 -0
  35. package/src/cli/codex-handoff-start.test.mjs +194 -0
  36. package/src/cli/codex-hook.mjs +276 -0
  37. package/src/cli/codex-hook.test.mjs +293 -0
  38. package/src/cli/codex-host-primitive-audit.mjs +110 -0
  39. package/src/cli/codex-host-primitive-audit.test.mjs +75 -0
  40. package/src/cli/codex-restore-smoke.mjs +357 -0
  41. package/src/cli/codex-restore-source-audit.mjs +304 -0
  42. package/src/cli/codex-resume.mjs +138 -0
  43. package/src/cli/codex-rollback-model-visible-smoke.mjs +373 -0
  44. package/src/cli/codex-rollback-model-visible-smoke.test.mjs +255 -0
  45. package/src/cli/codex-sidecar-diagnostics.mjs +48 -0
  46. package/src/cli/codex-sidecar-dry-run.mjs +85 -0
  47. package/src/cli/codex-summarize.mjs +224 -0
  48. package/src/cli/codex-threads.mjs +89 -0
  49. package/src/cli/codex-visibility-smoke.mjs +196 -0
  50. package/src/cli/codex-vscode-restore-smoke.mjs +226 -0
  51. package/src/cli/codex-vscode-rollback-smoke.mjs +114 -0
  52. package/src/cli/doctor.mjs +503 -1
  53. package/src/cli/doctor.test.mjs +542 -3
  54. package/src/cli/handoff-preview.mjs +78 -0
  55. package/src/cli/help.test.mjs +64 -0
  56. package/src/cli/install.mjs +226 -3
  57. package/src/cli/install.test.mjs +205 -4
  58. package/src/cli/trim.mjs +564 -0
  59. package/src/codex-app-server.mjs +1816 -0
  60. package/src/codex-app-server.test.mjs +512 -0
  61. package/src/codex-auto-refresh.mjs +194 -0
  62. package/src/codex-auto-refresh.test.mjs +182 -0
  63. package/src/codex-capture.mjs +235 -0
  64. package/src/codex-capture.test.mjs +393 -0
  65. package/src/codex-handoff-model-smoke.mjs +114 -0
  66. package/src/codex-handoff-model-smoke.test.mjs +89 -0
  67. package/src/codex-handoff-smoke.mjs +124 -0
  68. package/src/codex-handoff-smoke.test.mjs +103 -0
  69. package/src/codex-handoff.mjs +331 -0
  70. package/src/codex-handoff.test.mjs +220 -0
  71. package/src/codex-host-primitive-audit.mjs +374 -0
  72. package/src/codex-host-primitive-audit.test.mjs +208 -0
  73. package/src/codex-restore-smoke.test.mjs +639 -0
  74. package/src/codex-restore-source-audit.mjs +1348 -0
  75. package/src/codex-restore-source-audit.test.mjs +623 -0
  76. package/src/codex-resume.test.mjs +242 -0
  77. package/src/codex-rollout-memory.mjs +711 -0
  78. package/src/codex-rollout-memory.test.mjs +610 -0
  79. package/src/codex-sidecar-cli.test.mjs +75 -0
  80. package/src/codex-sidecar.mjs +246 -0
  81. package/src/codex-sidecar.test.mjs +172 -0
  82. package/src/codex-summarize.test.mjs +143 -0
  83. package/src/codex-thread-identity.mjs +23 -0
  84. package/src/codex-thread-index.mjs +173 -0
  85. package/src/codex-thread-index.test.mjs +164 -0
  86. package/src/codex-usage.mjs +110 -0
  87. package/src/codex-usage.test.mjs +140 -0
  88. package/src/codex-visibility-smoke.test.mjs +222 -0
  89. package/src/codex-vscode-restore-smoke.mjs +206 -0
  90. package/src/codex-vscode-restore-smoke.test.mjs +325 -0
  91. package/src/codex-vscode-rollback-smoke.mjs +90 -0
  92. package/src/codex-vscode-rollback-smoke.test.mjs +290 -0
  93. package/src/db-schema.test.mjs +96 -0
  94. package/src/db.mjs +14 -1
  95. package/src/haiku-summarizer.mjs +267 -26
  96. package/src/haiku-summarizer.test.mjs +282 -0
  97. package/src/handoff-preview.test.mjs +108 -0
  98. package/src/handoff-record.mjs +294 -0
  99. package/src/handoff-record.test.mjs +226 -0
  100. package/src/hook-entrypoints.test.mjs +286 -0
  101. package/src/package-files.test.mjs +19 -0
  102. package/src/prompt-submit.mjs +9 -6
  103. package/src/resume-context.mjs +58 -171
  104. package/src/resume-context.test.mjs +177 -0
  105. package/src/session-start.mjs +85 -26
  106. package/src/state-file.mjs +50 -6
  107. package/src/state-file.test.mjs +50 -0
  108. package/src/token-monitor.mjs +14 -10
  109. package/src/token-monitor.test.mjs +27 -0
  110. package/src/trim-cli.test.mjs +1584 -0
  111. package/src/trim-model.mjs +584 -0
  112. package/src/trim-model.test.mjs +568 -0
  113. package/src/turn-processor.mjs +17 -10
  114. package/src/vscode-task.mjs +33 -10
  115. package/src/vscode-task.test.mjs +19 -9
  116. package/src/cli/save-inflight.mjs +0 -81
@@ -0,0 +1,528 @@
1
+ # Throughline: Codex 両対応 + Rollback Trim 実装計画
2
+
3
+ この文書は TODO を兼ねた実装計画です。
4
+
5
+ ## この文書の位置づけ
6
+
7
+ この文書は **これまでの統合実装計画と実装履歴** です。
8
+ 2026-05-06 以降の次フェーズ実装順、TODO、進捗チェックは [THROUGHLINE_CODEX_FIRST_ROADMAP.md](THROUGHLINE_CODEX_FIRST_ROADMAP.md) を正として扱う。
9
+
10
+ 元文書:
11
+
12
+ - [THROUGHLINE_CODEX_DUAL_SUPPORT.md](THROUGHLINE_CODEX_DUAL_SUPPORT.md)
13
+ - [throughline-rollback-context-trim-insight.md](throughline-rollback-context-trim-insight.md)
14
+
15
+ 関係性:
16
+
17
+ | 文書 | この計画での扱い |
18
+ |---|---|
19
+ | [THROUGHLINE_CODEX_FIRST_ROADMAP.md](THROUGHLINE_CODEX_FIRST_ROADMAP.md) | 2026-05-06 以降の次フェーズ計画。Codex primary 実用化を先行し、Codex Rewind 互換を完成させてから Claude 側を詰める |
20
+ | [THROUGHLINE_CODEX_DUAL_SUPPORT.md](THROUGHLINE_CODEX_DUAL_SUPPORT.md) | Claude / Codex 両対応の architecture brief。主に Phase 1-5 に対応 |
21
+ | [throughline-rollback-context-trim-insight.md](throughline-rollback-context-trim-insight.md) | rollback trim の design insight。主に Phase 6-8 に対応 |
22
+
23
+ この計画は両者の合流点であり、Claude contract 固定を先行させる。rollback trim は実測 spike を通るまで本線実装にしない。
24
+
25
+ ## 現在の判断
26
+
27
+ 2 つの計画は矛盾しない。ただし、同時に実装へ入ると境界が曖昧になる。
28
+
29
+ 先に固定するべきものは **Claude contract**。Throughline は Claude Code を主軸としてきたプロジェクトであり、Codex 対応や rollback trim は Claude path を置き換えるものではない。
30
+
31
+ 実装順は次を基本線にする。
32
+
33
+ ```text
34
+ Claude contract 固定
35
+ -> agent-neutral handoff 境界
36
+ -> Codex sidecar / handoff projection
37
+ -> rollback / inject primitive spike
38
+ -> /tl-trim 系 UX
39
+ ```
40
+
41
+ rollback trim は最終的な理想に近いが、host primitive の実測が必要なため、最初の本線実装にしない。
42
+
43
+ ## 絶対に守ること
44
+
45
+ - Claude hooks、slash command、transcript parsing、handoff baton、SessionStart resume behavior を Codex 用に置き換えない。
46
+ - Claude-facing field / command / DB semantics を rename しない。
47
+ - Codex 対応は adapter / projection として足す。
48
+ - `thread/rollback` / `thread/inject_items` は live host primitive として実測済み。2026-05-06 incident 後に Codex guarded execute / auto-refresh は一時停止したが、2026-05-08 の controlled rollback model-visible smoke が再現しなかったため、過剰 blocker は解除済み。現在は [THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md](THROUGHLINE_CODEX_TRIM_ROLLBACK_FIX_PLAN.md) を優先し、DB memory と rollout/app-server turn-count guard を必須にする。Claude `/rewind` 自動化はまだ有効化しない。
49
+ - fallback や silent recovery で失敗を隠さない。互換モードは条件と理由を明示する。
50
+
51
+ ## 運用ルール
52
+
53
+ - この計画書のチェックボックスは、実装 PR / 作業単位ごとに更新する。
54
+ - Phase の完了条件は、継続運用ルールではなく、その Phase で閉じられる成果物だけにする。
55
+ - README には実装済み behavior だけを載せる。実装前の将来計画をユーザー向け仕様として見せない。
56
+
57
+ ## Phase 0: 計画とドキュメントの整列
58
+
59
+ 目的: 作業者が Claude 正本を見失わない状態にする。
60
+
61
+ - [x] `AGENTS.md` を追加し、`CLAUDE.md` 正本参照と Claude 主軸を明記する。
62
+ - [x] `CLAUDE.md` の必読ドキュメントに、この計画書と元 2 文書を位置付ける。
63
+ - [x] README には実装済み behavior だけを載せる方針を運用ルールに明記する。
64
+
65
+ 完了条件:
66
+
67
+ - [x] Claude / Codex どちらの作業者も、`CLAUDE.md` が正本であることを迷わない。
68
+ - [x] 2 つの元計画とこの実装計画の関係が docs 上で追える。
69
+
70
+ ## Phase 1: Claude Contract Audit
71
+
72
+ 目的: Codex 対応の前に、壊してはいけない現行挙動を棚卸しする。
73
+
74
+ 確認対象:
75
+
76
+ - [x] Claude transcript file shape
77
+ - [x] `extractDetailBlocks` の tool input / output / thinking / image / system 分類
78
+ - [x] `/tl` による `handoff_batons` 作成
79
+ - [x] `save-inflight` による `memo_text` 保存
80
+ - [x] `SessionStart` による baton consume と session merge
81
+ - [x] `resume-context` の注入順序
82
+ - [x] L1 / L2 / L3 保存境界
83
+ - [x] `origin_session_id` を維持する merge semantics
84
+ - [x] VSCode task provisioning の hook 呼び出し境界
85
+ - [x] Stop hook async 登録
86
+ - [x] background Claude subagent / external review task の有無。無ければ migration は no-op と記録する
87
+
88
+ 成果物:
89
+
90
+ - [x] `CLAUDE.md` に現行 contract の索引が不足していれば追記する。
91
+ - [x] 既存テストで固定済みの contract と、未固定の contract を一覧化する。
92
+ - [x] 未固定のうち Codex 対応で壊れやすいものを Phase 2 の test TODO に送る。
93
+
94
+ 完了条件:
95
+
96
+ - [x] 「Codex 対応で触ってはいけない Claude 境界」が文書と test TODO の両方で見える。
97
+
98
+ Audit result (2026-05-06):
99
+
100
+ | Contract | Current evidence | Status |
101
+ |---|---|---|
102
+ | Claude transcript block parsing | `src/transcript-reader.test.mjs` covers tool input/output pairing, thinking, image, hook attachments, unknown attachments, ANSI stripping, array content, current-turn slicing | Mostly fixed |
103
+ | `/tl` baton table behavior | `src/baton.test.mjs` covers TTL, project scoping, consume deletion, memo read/write, memo preservation | Fixed at baton module level |
104
+ | `save-inflight` memo write | `src/baton.test.mjs` covers `updateBatonMemo`; `src/cli/save-inflight.mjs` has CLI behavior but no isolated CLI test | Module fixed, CLI entrypoint not fixed |
105
+ | Session merge semantics | `src/session-merger.test.mjs` covers merge target chain, self-handoff refusal, predecessor age guard, already merged guard, row movement, `merged_into` | Fixed at merger module level |
106
+ | SessionStart baton consume + resume injection | `src/hook-entrypoints.test.mjs` covers isolated subprocess baton consume, merge, memo injection, and resume context output | Fixed at subprocess fixture level |
107
+ | `resume-context` output order | `src/resume-context.test.mjs` covers memo → latest thinking → L1 → L2 → footer, empty context, and current-origin exclusion | Fixed |
108
+ | L1/L2 rolling window | `src/turn-processor.test.mjs` covers `L2_WINDOW = 20`, distinct origin×turn counting, oldest unsummarized selection, merge-aware summarization window | Core selection fixed |
109
+ | L2/L3 DB persistence from hook | `src/hook-entrypoints.test.mjs` covers `process-turn` subprocess with isolated DB, L2 bodies, L3 thinking/tool input/tool output details | Fixed at subprocess fixture level |
110
+ | `origin_session_id` contract | `src/session-merger.test.mjs` and `src/turn-processor.test.mjs` cover origin-aware merge and turn counting | Fixed for core semantics |
111
+ | VSCode task provisioning | `src/vscode-task.test.mjs` covers task detection, JSON/JSONC handling, broken task repair, notices, gitignore recommendation; hook entrypoints call it under try/catch | Core fixed |
112
+ | Stop hook async registration | `src/cli/install.test.mjs` asserts Stop has `async: true`, SessionStart/UserPromptSubmit stay synchronous | Fixed |
113
+ | Background Claude subagent / external review task | The only current subagent-like external model call is L2 → L1 summarization in `src/haiku-summarizer.mjs` via `claude -p`; `/tl` in-flight memo is written by the main Claude agent through `.claude/commands/tl.md` + `save-inflight` | Migrate only L2 → L1 summarization path |
114
+
115
+ `CLAUDE.md` already contains the relevant source map, hooks contract, schema v7 summary, and test index, so Phase 1 did not require additional `CLAUDE.md` edits.
116
+
117
+ ## Phase 2: Claude Behavior Lock Tests
118
+
119
+ 目的: adapter 分離の前に、現行 Claude path の回帰検出を強くする。
120
+
121
+ 追加または確認するテスト:
122
+
123
+ - [x] 既存 `transcript-reader.test.mjs` で Claude transcript の L3 抽出がどこまで固定済みか確認する。
124
+ - [x] hook entrypoint のテスト方法を決める。`turn-processor.mjs` / `session-start.mjs` / `prompt-submit.mjs` は import-safe な `run()` export にし、CLI / 直接実行時だけ hook body を走らせる。
125
+ - [x] CLI subprocess fixture を使う場合は、必ず temp HOME / isolated DB を使う。`src/hook-entrypoints.test.mjs` は `HOME` / `USERPROFILE` を temp dir に差し替えて実ユーザー DB を触らない。
126
+ - [x] 不足があれば、turn-processor + DB 保存まで含む integration test で L2 body と L3 details の保存を固定する。
127
+ - [x] assistant thinking が `details.kind = 'thinking'` として保存されることを、既存テストまたは integration test で固定する。
128
+ - [x] `/tl` 相当の prompt-submit が baton を作る。
129
+ - [x] `save-inflight` が同一 project baton に memo を保存する。
130
+ - [x] `SessionStart` が TTL 内 baton を consume し、resume context に in-flight memo を含める。
131
+ - [x] baton が無い場合は引き継ぎをしない。
132
+ - [x] `buildResumeContext` の現行出力順序を fixture で固定する。
133
+ - [x] Claude-facing schema / field name の snapshot または focused assertion を置く。
134
+
135
+ 注意:
136
+
137
+ - 既存テストで十分固定できているものは、新規テストを重複追加しない。
138
+ - fixture は Claude transcript の現物仕様を表す。Codex 用 fixture と混ぜない。
139
+
140
+ Phase 2 implementation result (2026-05-06):
141
+
142
+ - `turn-processor.mjs` / `session-start.mjs` / `prompt-submit.mjs` は import-safe な `run()` export に変更した。
143
+ - `bin/throughline.mjs` は既存 command surface を維持し、各 hook の `run()` を明示実行する。
144
+ - `src/hook-entrypoints.test.mjs` は temp HOME / isolated DB で hook subprocess を検証する。
145
+ - `src/resume-context.test.mjs` は引き継ぎ注入順序を固定する。
146
+ - `src/db-schema.test.mjs` は schema v7 の Claude-facing table / field / index 名を固定する。
147
+
148
+ 完了条件:
149
+
150
+ - [x] Codex adapter 追加前の Claude path 主要テストが通る。2026-05-06 に `npm test` で 233 tests pass。Codex guarded trim 統合後は nested CLI tests を含めて 324 tests pass。
151
+ - [x] Claude transcript / handoff behavior の破壊が test failure になる。
152
+
153
+ ## Phase 3: Agent-neutral Handoff Core
154
+
155
+ 目的: Claude transcript から直接 Codex context block を作るのではなく、安定した中間表現を作る。
156
+
157
+ 設計 TODO:
158
+
159
+ - [x] 現行 `resume-context` が組み立てている情報を audit する。
160
+ - [x] `HandoffRecord` または同等の stable object を、まず DB 永続化しない projection として定義する。
161
+ - [x] `HandoffRecord` に含める最小フィールドを決める。
162
+ - session id
163
+ - project path
164
+ - intent(初期値は `continue implementation` などの固定値。DB 由来の推測はしない)
165
+ - constraints(初期値は Claude contract preservation などの固定値。DB 由来の推測はしない)
166
+ - L1 summary
167
+ - recent L2 bodies
168
+ - selected L3 references(初期実装では `throughline detail <時刻>` / `source_id` 参照。file path / line reference は既知の場合だけ付ける)
169
+ - in-flight memo
170
+ - source / origin session references
171
+ - [x] Claude resume context は、既存挙動を維持したまま必要なら `HandoffRecord` から生成できるようにする。
172
+ - [x] DB schema は Phase 3 では増やさない。永続化が必要になった場合のみ、根拠を添えて別途検討する。
173
+
174
+ 実装 TODO:
175
+
176
+ - [x] `src/` 内に handoff core module を追加する。
177
+ - [x] Claude adapter から handoff core へ依存方向を整理する。
178
+ - [x] handoff object の unit test を追加する。
179
+ - [x] `src/resume-context.test.mjs` で挙動差分なしを確認する。
180
+
181
+ Phase 3 implementation result (2026-05-06):
182
+
183
+ - `src/handoff-record.mjs` を追加した。DB 永続化はせず、schema v7 の `sessions` / `skeletons` / `bodies` / `details` から `handoff_record` v1 を projection する。
184
+ - `src/resume-context.mjs` は `HandoffRecord` から Claude-facing Markdown を描画する形に整理した。既存 SessionStart の出力 contract は維持する。
185
+ - `HandoffRecord` v1 は `session` / `source` / `intent` / `constraints` / `memory` / `references.l3` / `stats` を持つ。現時点の persisted writer は Claude transcript 由来なので `source.adapter` は `claude` 固定であり、Codex capture を実装するまでは agent-neutral な形をした Claude-origin projection として扱う。
186
+ - `references.l3` は `sourceId` と `throughline detail <HH:MM:SS>` 参照を持つ。file path / line reference は Phase 3 では必須にしない。
187
+ - `src/handoff-record.test.mjs` で stable projection、origin 除外、空 projection を固定した。
188
+
189
+ 完了条件:
190
+
191
+ - [x] Claude path は変わらない。
192
+ - [x] Codex adapter が Claude transcript internals を直接読む必要がない。
193
+
194
+ ## Phase 4: Codex Handoff Projection
195
+
196
+ 目的: `throughline_handoff` context block を生成する。
197
+
198
+ 設計 TODO:
199
+
200
+ - [x] `throughline_handoff` JSON schema を docs に固定する。
201
+ - [x] `SidecarContextBlock` に渡す references の最小形式を決める。`codex-sidecar` 実装上 `references[].path` は必須なので、DB / `throughline detail` 参照は `data.detailReferences` に置き、file path / line reference が既知の場合だけ top-level `references` を使う。
202
+ - [x] trust / source / kind の値を固定する。
203
+ - [x] Codex primary と Claude primary の違いを明文化する。
204
+ - [x] Codex-on-Codex recursion policy は、まず明示 config / explicit mode として表現する。自動 host-agent detection は初期実装に入れない。
205
+
206
+ 実装 TODO:
207
+
208
+ - [x] `HandoffRecord` から `throughline_handoff` block への converter を追加する。
209
+ - [x] fixture snapshot を追加する。
210
+ - [x] CLI から handoff projection preview を出力できる入口を検討する。
211
+
212
+ `throughline_handoff` v1 schema:
213
+
214
+ ```json
215
+ {
216
+ "kind": "throughline_handoff",
217
+ "source": "throughline",
218
+ "trust": "local",
219
+ "summary": "In-flight handoff: Next: continue",
220
+ "data": {
221
+ "throughlineHandoffSchemaVersion": 1,
222
+ "handoffRecordVersion": 1,
223
+ "sessionId": "session-id",
224
+ "projectPath": "/repo",
225
+ "sourceAgent": "claude",
226
+ "hostMode": "claude-primary",
227
+ "intent": "continue implementation",
228
+ "constraints": ["preserve existing Claude Code hook, slash command, transcript, baton, and resume behavior"],
229
+ "originSessionIds": ["old-session"],
230
+ "stats": {
231
+ "l1Rows": 1,
232
+ "l2Rows": 2,
233
+ "thinkingRows": 1,
234
+ "l3References": 2,
235
+ "preservedContextRows": 3
236
+ },
237
+ "memory": {
238
+ "inflightMemo": "Next: continue",
239
+ "latestThinking": [],
240
+ "l1Summaries": [],
241
+ "recentBodies": []
242
+ },
243
+ "detailReferences": [
244
+ {
245
+ "type": "throughline_detail",
246
+ "label": "tool_input:Bash",
247
+ "command": "throughline detail 12:00:01",
248
+ "sourceId": "toolu_1",
249
+ "detailKind": "tool_input",
250
+ "originSessionId": "old-session",
251
+ "turnNumber": 2
252
+ }
253
+ ]
254
+ }
255
+ }
256
+ ```
257
+
258
+ Fixed values:
259
+
260
+ - `kind`: `throughline_handoff`
261
+ - `source`: `throughline`
262
+ - `trust`: `local`
263
+ - `data.throughlineHandoffSchemaVersion`: `1` (`codex-sidecar` の `SidecarContextBlock` は top-level `schemaVersion` を保持しないため)
264
+ - `data.sourceAgent`: initially `claude`
265
+ - `data.hostMode`: explicit `claude-primary` / `codex-primary` / `unknown`; no automatic host detection in Phase 4
266
+
267
+ Phase 4 implementation result (2026-05-06):
268
+
269
+ - `src/codex-handoff.mjs` を追加し、`HandoffRecord` から `throughline_handoff` v1 JSON block を生成する。
270
+ - `data.detailReferences` は `throughline detail <HH:MM:SS>` command と `sourceId` を持つ DB reference として固定した。`codex-sidecar` の top-level `references` は file path が既知の場合だけ使う。
271
+ - `throughline handoff-preview [--session <id>] [--host-mode <mode>]` を追加し、sidecar 実行なしで JSON projection を確認できる入口を用意した。
272
+ - `src/codex-handoff.test.mjs` と `src/handoff-preview.test.mjs` で JSON shape と CLI preview を固定した。
273
+
274
+ 完了条件:
275
+
276
+ - [x] Codex が読むための context block を、Claude path を変えずに生成できる。
277
+ - [x] fixture で JSON shape が固定されている。
278
+
279
+ ## Phase 5: codex-sidecar Read-only Integration
280
+
281
+ 目的: Codex sidecar を review / explore / risk-check 用の独立 second pass として使えるか検証する。
282
+
283
+ 前提:
284
+
285
+ - `codex-sidecar diagnostics --project <repo> --preset review` が成功する環境だけを configured 以上と扱う。
286
+ - `codex` binary の存在だけでは利用可能とみなさない。
287
+ - sidecar unavailable / disabled 時に Claude behavior を維持するのは、明示された compatibility mode であり、hidden fallback ではない。
288
+ - `codex-sidecar` がこの環境で未導入なら、Phase 5 の外部 smoke は unresolved として記録してよい。ローカルの Claude contract / projection 実装をブロックしない。
289
+
290
+ TODO:
291
+
292
+ - [x] diagnostics 実行 wrapper を追加する。
293
+ - [x] diagnostics 結果に基づき、Codex sidecar unavailable / disabled / configured / operational / work-capable の状態表現を追加する。
294
+ - [x] diagnostics failure を明示的な unavailable として扱う。
295
+ - [x] L2 → L1 要約で、`codex-sidecar` が configured の場合は `codex-sidecar` を使う。
296
+ - [x] `codex-sidecar` が disabled / unavailable の場合は、現行 Claude Haiku 要約を維持する。
297
+ - [x] `/tl` in-flight memo は main Claude agent の slash command 手順なので、Codex sidecar へ移さない。
298
+ - [x] `codex_explore` read-only smoke を追加する。
299
+ - [x] `codex_review` または `codex_risk_check` の sidecar request dry-run を追加する。
300
+ - [x] structured result を保存または link する場所を決める。
301
+ - [x] Claude primary から Codex sidecar を呼ぶ場合の内部 docs を追加する。README は更新しない。
302
+ - [x] Codex primary から Codex sidecar を呼ぶ場合の禁止 / 許可条件を内部 docs に追加する。README は更新しない。
303
+
304
+ Phase 5 implementation result (2026-05-06):
305
+
306
+ - `src/codex-sidecar.mjs` を追加し、`diagnoseCodexSidecar()` で `disabled` / `unavailable` / `configured` を返す。
307
+ - `THROUGHLINE_CODEX_SIDECAR_DISABLED=1` は明示的な `disabled`。`codex-sidecar` command 不在、spawn failure、diagnostics non-zero は `unavailable`。
308
+ - `configured` は `codex-sidecar diagnostics --project <repo> --preset <preset>` が exit 0 の場合だけ。
309
+ - `operational` / `work-capable` は status enum として予約したが、read-only / work smoke が未実装なので diagnostics wrapper はまだ返さない。
310
+ - `THROUGHLINE_CODEX_SIDECAR_BIN` で明示 command を指定できる。見つからない場合に別 path へ隠れて fallback しない。
311
+ - Windows では npm global bin の `.cmd` shim を解決できるよう、`codex-sidecar` subprocess も shell wrap する。これは既存の Claude CLI subprocess と同じ OS 境界対策。
312
+ - `throughline codex-sidecar-diagnostics --project <repo> [--preset review]` を追加し、JSON status を出力する。
313
+ - `throughline codex-sidecar-dry-run --project <repo> --preset review|risk-check [--context-file <json>] [prompt]` を追加し、sidecar request を Codex App Server へ送らず正規化 JSON として確認できる。
314
+ - `codex-sidecar-dry-run --turn-timeout-ms <ms>` は local subprocess timeout だけでなく、sidecar request の `turnTimeoutMs` にも反映する。
315
+ - `.codex-sidecar.yml` を追加後、この環境で 2026-05-06 に実行した diagnostics は `configured`。
316
+ - sample `throughline_handoff` context を使った read-only `codex-sidecar explore` smoke は 2026-05-06 に成功。`src/handoff-record.mjs` を source of truth、`src/resume-context.mjs` / `src/codex-handoff.mjs` を projection として正しく参照できた。
317
+ - sample `throughline_handoff` context を使った `review` / `risk-check` dry-run は 2026-05-06 に成功。`risk-check` は `claude-hooks` / `transcript-parsing` / `sqlite-memory` / `codex-sidecar` / `secrets` focus を保持した。
318
+ - structured result の保存 / link 方針: Throughline の L1/L2/L3 memory tables へ sidecar 結果を混ぜない。read-only 実行結果は sidecar の structured JSON stdout を一次成果物とし、実行ログは `rawEventLogRef` を canonical link として扱う。Throughline 側で永続 index が必要になった場合だけ、将来 `sidecar_runs` 相当の別 table / 別 artifact に `workflow` / `preset` / `status` / `rawEventLogRef` / `created_at` を保存する。
319
+ - `src/haiku-summarizer.mjs` は L2 → L1 要約時に `codex-sidecar` configured なら `summarize-l1` preset を使い、disabled / unavailable / sidecar run failure の場合は現行 Haiku 経路に戻す。
320
+ - `summarize-l1` の sidecar result parser は、旧 fixture の `{status:"ok", summary}` と stable `SidecarResult` の `{summary, confidence, recommendedNextAction}` の両方を受け付ける。
321
+ - `/tl` in-flight memo は `.claude/commands/tl.md` が現行メイン Claude に書かせるものであり、subagent / sidecar 置換対象ではない。
322
+
323
+ 完了条件:
324
+
325
+ - [x] sidecar が無い環境で Claude behavior が維持される。
326
+ - [x] sidecar がある環境では read-only second pass が再現可能に動く。無い環境では unavailable / unresolved として記録される。
327
+ - [x] hidden fallback なしで状態が説明される。
328
+
329
+ ## Phase 6: Rollback / Inject Spike
330
+
331
+ 目的: rollback trim を本線実装する前に、host primitive の実挙動を測る。
332
+
333
+ 前提:
334
+
335
+ - Phase 6 は外部 host primitive の試験であり、この環境で Codex app-server または Claude rewind automation が検証できない場合は unresolved として記録してよい。
336
+ - unresolved の場合、Phase 8 では自動 rollback 実装に進まず、dry-run / 手動案内までに留める。
337
+
338
+ Codex spike TODO:
339
+
340
+ - [x] 小さな test thread を開始する。
341
+ - [ ] 複数 turn を作る。単一 turn の full rollback は検証済み。partial rollback は Throughline 統合実装時の harness で追加検証する。
342
+ - [x] Codex の host identity model を記録する。`thread_id`、turn index、rollout JSONL、project path の対応を確認する。
343
+ - [ ] `thread/rollback` を partial `numTurns` で呼ぶ。複数 turn harness 未作成のため未完了。
344
+ - [x] `thread/rollback` を full または near-full `numTurns` で呼ぶ。
345
+ - [x] rollback 後の `thread/read includeTurns:true` を確認する。
346
+ - [x] rollback 後の rollout JSONL を確認する。
347
+ - [x] `thread/inject_items` に最小 memory item を渡す。
348
+ - [x] 次 turn で injected memory が model-visible か確認する。
349
+ - [x] `thread/resume` 後も rollback marker と injected memory が効くか確認する。
350
+ - [x] ローカルファイル変更が戻らないことを確認する。2026-05-06 の Throughline 統合 smoke で一時ファイルを置いたまま Codex guarded execute を行い、rollback 後も同一 hash で残ることを確認した。
351
+
352
+ Claude spike TODO:
353
+
354
+ - [ ] `/rewind` conversation-only の手動 UX を確認する。
355
+ - [ ] 外部ツールから自動化できる surface があるか確認する。
356
+ - [ ] 自動化できない場合の `/rewind conversation only` + `/tl restore` 手順を設計する。
357
+ - [ ] VSCode extension と CLI で挙動差があるか確認する。
358
+
359
+ 成果物:
360
+
361
+ - [x] spike 結果を docs に記録する。
362
+ - [x] 成功 / 失敗 / unknown を分ける。
363
+ - [x] 失敗を隠す代替実装を入れない。
364
+
365
+ Phase 6 result (2026-05-06):
366
+
367
+ - `codex-sidecar` read-only `explore` smoke と `review` / `risk-check` dry-run は成功。
368
+ - Codex CLI `0.128.0-alpha.1` の app-server schema で `thread/read`、`thread/resume`、`thread/rollback`、`thread/inject_items`、`turn/start` を確認した。
369
+ - `stdio://` transport は newline-delimited JSON で実測通過した。`initialize` 後に `thread/read includeTurns:true` が persisted thread を読める。
370
+ - `thread/rollback` は persisted thread を直接対象にすると `thread not found` を返す。`thread/resume` で loaded thread にしてから呼ぶ必要がある。
371
+ - 検証 thread `019dfaba-f87e-7f41-a144-d5ca7c6dd7f9` で、1 turn を `thread/rollback { numTurns: 1 }` し、`thread/read includeTurns:true` が 0 turns を返すことを確認した。
372
+ - `thread/inject_items` に raw Responses API item `{ type: "message", role: "developer", content: [{ type: "input_text", text: "..." }] }` を渡し、次の `turn/start` で injected memory が model-visible になることを確認した。marker `TL_PHASE6_INJECT_OK` を正しく返した。
373
+ - その後の Codex primary 実装で、`codex-resume` が描画する active-work developer message も実 Codex host で model-visible になることを確認した。marker `TL_CODEX_VISIBLE_REAL_20260506_C` が `item/agentMessage/delta` に出た。詳細な実測値は [THROUGHLINE_CODEX_FIRST_ROADMAP.md](THROUGHLINE_CODEX_FIRST_ROADMAP.md) の Phase 3 result を正とする。
374
+ - さらに `thread/inject_items` 後にもう一度 `thread/resume` してから `turn/start` を呼ぶ smoke も追加し、実 Codex host で marker `TL_CODEX_RESUME_AFTER_INJECT_REAL_20260506` が `item/agentMessage/delta` に出ることを確認した。
375
+ - Codex host primitive は live app-server 上では実測済み。ただし restart-safe durability は未証明。現在は明示 `--codex-thread-id` または env thread identity と rollout/app-server turn count guard が live mutation の最低条件であり、durable success は別分類で扱う。2026-05-06 incident 後はいったん Codex Stop hook 後の automatic refresh mutation を blocked としたが、2026-05-08 unblock 後は verified usage 90% 以上で guarded rollback / inject を試行する。
376
+ - Claude `/rewind conversation only` は手動 UX として扱う。外部ツールからの自動化 surface は未確認。Claude host の automatic rollback / inject は `manual-only`。
377
+ - Phase 8 では dry-run / preflight を本線にしつつ、Codex だけ guarded execute を追加した。Claude は manual-only のまま扱う。
378
+
379
+ 完了条件:
380
+
381
+ - [x] rollback trim を自動実装してよい host と、手動案内に留める host が判断できる。Codex は 2026-05-08 unblock 後、verified usage 90% 以上の Stop hook auto-refresh と明示 execute を許可する。Claude は manual-only。
382
+
383
+ ## Phase 7: Trim Handoff Model
384
+
385
+ 目的: rollback で削除する前に、Throughline が安全に復元できる memory model を固める。
386
+
387
+ TODO:
388
+
389
+ - [x] host identity model を整理する。Claude `session_id`、Codex `thread_id`、`project_path`、origin session / thread references の対応表を作る。Codex は `thread_id` と rollout JSONL を app-server で扱い、明示 identity と turn count guard がある場合だけ guarded execute へ進む。
390
+ - [x] current session / thread の captured turn count を記録または導出する方法を決める。
391
+ - [x] rollback 可能な最大 turn 数を計算する。
392
+ - [x] keep-recent の既定値を決める。
393
+ - [x] rollback 後に注入する curated memory の構成を決める。
394
+ - [x] L3 detail は inline 注入せず reference 化する方針を確認する。
395
+ - [x] trim 実行前の dry-run report を設計する。
396
+ - [x] trim audit log を DB に残すか決める。
397
+
398
+ Phase 7 result (2026-05-06):
399
+
400
+ - `src/trim-model.mjs` を追加し、schema v7 の `bodies` / `skeletons` から distinct `(origin_session_id, turn_number)` を数えて captured turn count を導出する。
401
+ - `keep-recent` 既定値は既存 resume context と同じ `N_RECENT_L2 = 20`。
402
+ - rollback candidate は `max(0, capturedTurns - keepRecent)`。`--all` は `keepRecent = 0`。
403
+ - curated memory preview は `HandoffRecord` から作る。L1 / recent L2 / latest thinking は preview に含めるが、L3 detail は inline 展開せず `throughline detail <time>` reference として扱う。
404
+ - trim audit log は現時点では DB に追加しない。dry-run / preflight / guarded execute の JSON 出力を evidence とする。永続化が必要になったら、memory tables ではなく専用 audit table / artifact に分離する。
405
+
406
+ 完了条件:
407
+
408
+ - [x] `/tl-trim` が何を削り、何を戻すかを実装前に説明できる。
409
+
410
+ ## Phase 8: `/tl-trim` UX
411
+
412
+ 目的: 同一 session / thread で model-visible context を整理する UX を追加する。
413
+
414
+ 候補コマンド:
415
+
416
+ ```text
417
+ /tl-trim
418
+ /tl-trim --dry-run
419
+ /tl-trim --keep-recent 20
420
+ /tl-trim --all
421
+ ```
422
+
423
+ TODO:
424
+
425
+ - [x] Claude 用 slash command と Codex 用 command surface を分ける。
426
+ - [x] `/tl-trim --dry-run` を先に実装する。
427
+ - [x] host が自動 rollback 非対応の場合、明示的な手動手順を返す。
428
+ - [x] 実行前に captured turns / keep turns / injected memory summary を表示する。
429
+ - [x] Codex dry-run では `--codex-thread-id` を受け取り、Claude / Throughline の `session_id` と Codex `thread_id` を混同しない形で plan に残す。
430
+ - [x] Codex non-dry-run の最初の統合として `--preflight` を追加する。これは app-server の initialize / read / resume だけを実行し、rollback / inject は送らない。
431
+ - [x] Codex の guarded execution として `--execute` を追加する。ただし `--host codex`、明示または env の Codex thread identity、rollout/app-server turn count guard を必須にし、実行後に model turn は開始しない。
432
+ - [ ] 自動 rollback 対応 host では、実行後に resume / injected memory が restart / reconnect 後も有効か検証する。Codex は Phase 6 spike、2026-05-06 guarded execute smoke、post-inject resume visibility smoke で live app-server 上の rollback/inject と injected memory visibility だけを確認した。2026-05-06 incident 後、これは restart-safe durability の完了条件を満たさない。
433
+ - [x] `doctor` に trim 関連診断を追加する。
434
+
435
+ Phase 8 partial implementation result (2026-05-06):
436
+
437
+ - `throughline trim --dry-run [--host claude|codex|unknown] [--keep-recent N] [--all] [--session <id>] [--codex-thread-id <id>] [--json]` を追加。
438
+ - `throughline trim --dry-run --memo-stdin` を追加。`/tl` が解決した「L1/L2 はあるが今やっている作業として認識されない」問題を `/tl-trim` でも再発させないため、current-work memo を curated memory preview の先頭に入れる。
439
+ - non-dry-run `throughline trim` は Claude / unknown host では automatic rollback / inject 未対応として exit 1 で明示拒否する。Codex host には `--execute` 経路が実装済み。2026-05-06 incident 後はいったん拒否したが、2026-05-08 unblock 後は明示 `--execute`、Codex thread identity、Throughline DB memory、rollout/app-server turn-count guard がそろえば mutation へ進む。
440
+ - `src/codex-app-server.mjs` を追加し、newline JSON framing、initialize / read / resume / rollback / inject / turn-start request builder、server line parser をテストで固定した。Codex guarded execute はこの helper を通り、model turn は開始しない。
441
+ - `--codex-thread-id` の明示入力を最優先で信頼する。明示入力が無い場合のみ、`THROUGHLINE_CODEX_THREAD_ID` / `CODEX_THREAD_ID` を current-thread identity signal として使う。最新 rollout 推測による automatic trim は行わない。
442
+ - `throughline trim --preflight --host codex --codex-thread-id <id> [--json]` を追加した。これは `thread/read` と `thread/resume` が対象 thread に届くことを確認し、`rollbackRequestPreview` を返すが、`thread/rollback` / `thread/inject_items` は送らない。
443
+ - `codex-rollout` source の場合、preflight は rollout 側 active turn count と app-server `thread/read` / `thread/resume` の turn count を突き合わせる。不一致または app-server count 不明なら `preflight-refused` として止まり、rollback / inject は送らない。
444
+ - 同日、検証 thread `019dfaba-f87e-7f41-a144-d5ca7c6dd7f9` に実 app-server preflight を当て、`readTurns: 1` / `resumedTurns: 1` / `rollbackSent: false` / `injectSent: false` を確認した。
445
+ - `throughline trim --execute --host codex --codex-thread-id <id> [--json]` を追加した。2026-05-06 incident 後は既定で拒否し、2026-05-07 追加修正では host primitive audit gate も置いた。2026-05-08 unblock 後はこの env gate / host primitive audit gate を外し、app-server の `thread/read`、`thread/resume`、`thread/rollback`、`thread/inject_items`、確認用 `thread/read` へ進む。host primitive audit と restore-safety は diagnostic-only。
446
+ - 実 app-server smoke では `thread/inject_items` の直後に返る turn 配列が、注入 item の可視化より早い場合があると分かった。その後の current-thread live run で、現行 Codex host の developer memory injection は item-level で、即時 `thread/read` の turn count を増やさない場合があることも確認した。そのため `--execute` は `thread/inject_items` の応答に turn list があればその turn count を期待値とし、応答に turn list がなければ rollback 後 turn count を期待値として post-inject `thread/read` を短く poll する。`postInjectVisibilityCheck` は `match` / `timeout` / `unchecked` を記録する。CLI 外側の status は `executed` ではなく、live mutation だけなら `execute-sent-live-only`、timeout や durable evidence 不足なら `execute-unverified`、rollout に新 rollback marker と active-work memory injection が観測された場合は `execute-durable-verified` とする。restore-safety は durable mutation evidence とは別の diagnostic として表示する。exit 0 は `execute-durable-verified` に限る。
447
+ - `codex-rollout` source の guarded execute は rollback 前に同じ turn count check を実行する。不一致または app-server count 不明なら `execute-refused` として止まり、`thread/rollback` / `thread/inject_items` は送らない。
448
+ - `--execute` が注入する item は `role: "developer"` の raw Responses message item で、中身は `memoryPreview.text`。`memoryPreview.text` は Reading Contract、Active Work Thread、Continuation Instruction を含むため、L2 を単なる過去ログではなく現在タスクの作業文脈として読む前提を維持する。
449
+ - `--execute` は model turn を開始しない。2026-05-06 の実機 smoke では、現在 Codex thread に対して guarded execute が `rollbackSent: true` / `injectSent: true` まで進み、その後の read-only preflight で rollout/app-server turn count が match に戻ることを確認した。これは live app-server 上の確認であり、restart-safe durability の証明ではない。実ファイル付き smoke では rollback 1 turn 後に一時ファイル `THROUGHLINE_CODEX_ROLLBACK_SMOKE.tmp` が同一 hash のまま残り、context rollback が worktree を戻さないことも確認した。注入 item の可視化は即時 read では遅れる場合があるため、上記 post-inject poll を入れた。
450
+ - fake app-server テストで、preflight は rollback / inject を送らないこと、execute は明示 `--execute` で `read -> resume -> rollback -> inject -> read...` の順に curated memory を注入し、post-inject read が遅れて可視化される場合も待つことを固定した。
451
+ - `throughline codex-threads [--json] [--all-projects] [--limit N]` を追加した。これは `~/.codex/session_index.jsonl` と `~/.codex/sessions/**/rollout-*.jsonl` を read-only に読み、現在 project の Codex thread id 候補を表示する。候補を出すだけで、自動 trim の対象 thread として採用しない。
452
+ - `--host codex --codex-thread-id <id>` の計画作成では、明示 thread id と現在 project に一致する rollout JSONL があれば `codex-rollout` を trim source として使う。これにより Throughline DB の `bodies` が 0 件でも、Codex 側の active turns から rollback candidate と memory preview を作れる。
453
+ - `codex-rollout` source は `event_msg:task_started` を turn として扱い、`event_msg:thread_rolled_back` を適用して active turns を再構成する。rollback 済み tail は current memory preview に戻さない。
454
+ - Claude slash command [.claude/commands/tl-trim.md](../.claude/commands/tl-trim.md) を追加し、現行 Claude が current-work memo を書いてから `throughline trim --dry-run --host claude --memo-stdin` を呼ぶ dry-run UX にした。
455
+ - `throughline install` / `uninstall` は `/tl-trim` も配布 / 削除する。
456
+ - `throughline doctor --trim --host claude|codex|unknown` を追加し、default keep-recent、automatic rollback / inject 可否、manual procedure を表示する。Codex host では `THROUGHLINE_CODEX_THREAD_ID` / `CODEX_THREAD_ID` の検出結果も表示する。
457
+ - `resume-context` の L2 section を「直近のターン履歴」から「現在進行中の作業履歴 (active work thread)」へ寄せ、読み方の契約を追加した。L2 全体を現在真実とみなすのではなく、古い順の active context として読み、後続行が前の仮説を上書きし得ることを明示する。
458
+
459
+ Current-work framing research note (2026-05-06):
460
+
461
+ - 「今取り込み中の内容」をモデルに認識させる専用の汎用フラグは見つからない。Claude / Codex とも、通常は role / instruction authority、現在 turn への近さ、明示的な section boundary、metadata、最新 user request との接続で文脈の読み方が決まる。
462
+ - Codex CLI は initial prompt を role 付き item list として組み立て、`system` / `developer` / `user` / `assistant` の authority order を使う。AGENTS 系 project docs は user instruction として集約され、より specific なものが後ろに入る。参考: [OpenAI: Unrolling the Codex agent loop](https://openai.com/index/unrolling-the-codex-agent-loop/)。
463
+ - Claude Code の `CLAUDE.md` は launch 時に context へ読み込まれる project / user / local instruction であり、永続的な作業状態そのものではない。scope と specificity で効かせる。参考: [Claude Code memory docs](https://code.claude.com/docs/en/memory)。
464
+ - Anthropic long-context tips は、長い data は上、query / instructions は後ろに置くと性能が上がる場合があるとし、複数 document は XML / metadata で構造化することを推奨している。参考: [Claude long context prompting tips](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/long-context-tips)。
465
+ - OpenAI prompt engineering docs / Cookbook は、Markdown / XML の section boundary、明示 instruction、long context では instruction を冒頭と末尾の両方に置く構成を推奨している。参考: [OpenAI prompt engineering](https://platform.openai.com/docs/guides/prompt-engineering) / [GPT-4.1 Prompting Guide](https://cookbook.openai.com/examples/gpt4-1_prompting_guide)。
466
+ - Lost in the Middle は、長文 context 内の関連情報位置で性能が落ち、冒頭または末尾の情報が使われやすいことを示す。参考: [Liu et al., 2023](https://arxiv.org/abs/2307.03172)。
467
+ - 結論: in-flight memo は現状の強い補助線として残す。ただし本質は memo そのものではなく、L1/L2 を「現在タスクに使う作業コンテキスト」として role / section / recency / repetition で明示すること。全 L2 を「現在も正しい事実」とラベルするのは危険なので避け、古い順、後続優先、supersession rule、detail-on-demand を冒頭と末尾に置く。
468
+ - 実装反映: `resume-context` と `trim` preview は、L2 section を active work thread として構造化し、冒頭の reading contract と末尾の continuation instruction の両方で同じ読み方を繰り返す。
469
+
470
+ 完了条件:
471
+
472
+ - [ ] 対応 host では同一 session / thread の context trim が動く。Codex guarded execute は実機 smoke で live rollback / inject を完了したが、restart-safe durability は未証明のため完了扱いしない。
473
+ - [x] Codex では guarded execute path が fake app-server 上で rollback / inject 順序を満たす。
474
+ - [x] Codex では明示 thread id の rollout JSONL から active turns / memory preview を作り、DB 未捕捉の Codex 作業でも dry-run / preflight / guarded execute の plan source にできる。
475
+ - [x] Codex では `codex-rollout` active turn count と app-server read/resume turn count を突き合わせ、差分がある場合は mutation 前に拒否する。
476
+ - [x] 非対応 host では、何が足りないかを明示して止まる。
477
+ - [x] Claude の既存 `/tl` baton handoff は残る。
478
+
479
+ ## Phase 9: Release Readiness
480
+
481
+ 目的: 既存ユーザーに誤解なく出せる状態にする。
482
+
483
+ TODO:
484
+
485
+ - [x] README に Claude primary / Codex sidecar / rollback trim の関係を書く。
486
+ - [x] `CLAUDE.md` の実装済みファイル一覧を更新する。
487
+ - [x] `PUBLIC_RELEASE_PLAN.md` に status を反映する。
488
+ - [x] CHANGELOG を更新する。
489
+ - [x] 推奨 test command を通す。
490
+ - [x] Codex sidecar が無い環境の動作確認を行う。
491
+ - [x] Claude-only 環境の動作確認を行う。
492
+ - [x] npm tarball に README 参照先 docs / slash command / new CLI files が入ることを確認する。
493
+
494
+ 完了条件:
495
+
496
+ - [x] Claude-only の Throughline として従来通り動く。
497
+ - [x] Codex sidecar integration の可用性が明示されている。
498
+ - [x] rollback trim の対応 host / 非対応 host が明示されている。
499
+
500
+ Verification refresh (2026-05-06):
501
+
502
+ - `node --test src/vscode-task.test.mjs`: 68 tests pass。Claude-facing `<system-reminder>` notice は assertion 対象テスト内で捕捉され、通常の TAP output には漏れない。
503
+ - `node --test src/codex-sidecar.test.mjs src/haiku-summarizer.test.mjs src/codex-sidecar-cli.test.mjs`: 16 tests pass。Windows npm bin shim 用 shell wrap と sidecar/Haiku 互換経路を確認。
504
+ - `node --test src/codex-app-server.test.mjs src/trim-cli.test.mjs`: 24 tests pass。Codex guarded execute の post-inject visibility polling を含む。
505
+ - `codex-sidecar review --project . --preset review ...`: sidecar 側の structured-output validation は failed になったが、raw event log から 3 件の actionable finding を回収し、stable `SidecarResult` parser、`npm test` の nested test coverage、`.codex-sidecar.yml` allowed_paths を修正済み。
506
+ - `throughline codex-sidecar-diagnostics --project . --preset review`: `configured`。
507
+ - `codex-sidecar explore --project . --preset explore ...`: read-only smoke 成功。`src/token-monitor.mjs` が sidecar から read 可能であることを確認。生成される `.codex-sidecar/logs/` は runtime artifact として `.gitignore` 済み。
508
+ - `npm test`: nested `src/cli/*.test.mjs` coverage を含めて 324 tests pass。
509
+ - `git diff --check`: pass。
510
+ - `npm pack --dry-run`: 73 files。README 参照先 docs / slash command / new CLI files / `.codex-sidecar.yml` を含む。
511
+
512
+ ## Open Questions
513
+
514
+ - [ ] `HandoffRecord` projection で足りなくなる条件は何か。足りない場合だけ DB 永続化を再検討する。
515
+ - [ ] Codex sidecar result は DB に保存するか、artifact path を link するか。
516
+ - [ ] Codex primary mode の host-agent detection を、明示 config から自動判定へ拡張する条件は何か。
517
+ - [ ] rollback trim の default `keep-recent` は何 turn がよいか。
518
+ - [ ] Claude `/rewind` を自動化できない場合、Throughline はどこまで UX を持つべきか。
519
+
520
+ ## 当面の次タスク
521
+
522
+ - [x] Phase 2 の hook entrypoint test method を決める。
523
+ - [x] Phase 2 の不足 integration test を特定する。
524
+ - [x] Phase 3 の `HandoffRecord` projection 設計に入る。
525
+ - [x] Phase 4 の `throughline_handoff` JSON schema を docs に固定する。
526
+ - [x] Phase 5 の `codex-sidecar` diagnostics wrapper に入る。
527
+ - [x] Phase 8 の `/tl-trim --dry-run` を実装する。
528
+ - [x] Phase 8 の `doctor` trim 診断を追加する。