claude-code-tools 1.32.2__tar.gz → 1.32.3__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.
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/PKG-INFO +1 -1
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/__init__.py +1 -1
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_history_chain.py +176 -27
- claude_code_tools-1.32.3/claude_code_tools/codex_live_rollout.py +123 -0
- claude_code_tools-1.32.3/claude_code_tools/codex_rollout_db.py +59 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/find_claude_session.py +2 -2
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/find_codex_session.py +2 -2
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/port_codex_provider.py +12 -9
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/port_codex_to_claude.py +7 -4
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/port_service.py +1 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/resolve_session.py +122 -122
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/session_resolution.py +29 -3
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/session_utils.py +2 -6
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/pyproject.toml +2 -2
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/.gitignore +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/LICENSE +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/README.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/action_rpc.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/__init__.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/backends.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/cli.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/config.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/convert.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/discord_bot.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/http_frontend.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/locking.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/mattermost_bot.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/paths.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/readonly.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/registry.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/relay.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/serve.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/session.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/store.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/tmux.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/trust.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/agent_tunnel/turn_log.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/aichat.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/__init__.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/__main__.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/activity.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/cache.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/cli.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/detect.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/filters.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/model.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/render.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/amux/scan.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/claude_continue.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/cli_passthrough.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_app_server_rpc.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_continue.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_callback.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_cli.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_fingerprint.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_generation.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_legacy.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_models.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_process.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_reservation.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_resume.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_retry.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_reuse.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_state.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_supervisor.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_wait.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_server_worker.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/config.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/csv2gsheet.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/delete_session.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/dotenv_vault.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/env_safe.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/export_all.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/export_claude_session.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/export_codex_session.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/export_session.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/find_original_session.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/find_session.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/find_trimmed_sessions.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/fix_session.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/gdoc2docx.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/gdoc2md.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/github_wake.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/github_watch_daemon.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/github_watch_store.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/gsheet2csv.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/helper_sessions.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/issue_reply_delivery.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/legacy_session_wrappers.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/md2gdoc.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/move_account.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/msg/__init__.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/msg/cli.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/msg/hooks.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/msg/migrations.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/msg/models.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/msg/prompt_detect.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/msg/store.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/msg/watcher.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/node_menu_ui.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/port_claude_noise.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/port_claude_to_codex.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/port_codex_flatten.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/port_render.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/resolve_session_names.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/resolve_session_render.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/search_index.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/session_cli_resolution.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/session_lineage.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/session_menu.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/session_menu_cli.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/session_selection.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/smart_trim.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/smart_trim_core.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/tmux_cli_controller.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/tmux_execution_helpers.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/tmux_remote_controller.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/trim_in_place.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/trim_session.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/trim_session_claude.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/trim_session_codex.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_cli.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_cli_contract.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_cli_formatting.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_cli_identity_policy.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_cli_manifest.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_cli_projection.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_cli_rendering.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_cli_snapshots.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_cli_store_backends.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_processes.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_runs.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_store_io.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/workflow_validation.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/docs/agent-tunnel-spec.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/docs/claude-code-tmux-tutorials.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/docs/dot-zshrc.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/docs/find-claude-session.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/docs/intercom-spec.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/docs/lmsh.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/docs/local-llm-setup.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/docs/tmux-cli-instructions.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/docs/vault-documentation.md +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/hatch_build.py +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/node_ui/action_config.js +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/node_ui/menu.js +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/node_ui/package-lock.json +0 -0
- {claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/node_ui/package.json +0 -0
{claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/codex_history_chain.py
RENAMED
|
@@ -16,7 +16,8 @@ that was later rewound, for example) is not part of the history.
|
|
|
16
16
|
|
|
17
17
|
Each rollout contributes only its local delta: Codex drops the
|
|
18
18
|
``session_meta`` record of every segment and keeps one canonical
|
|
19
|
-
session meta.
|
|
19
|
+
session meta. A Claude port follows the live writer or SQLite selection.
|
|
20
|
+
Other file operations identify the current rollout by
|
|
20
21
|
(filename timestamp, rollout id), matching Codex's own
|
|
21
22
|
``find_thread_path_by_id_str``. All of this mirrors the Codex source
|
|
22
23
|
(``codex-rs/rollout/src/list.rs`` and
|
|
@@ -36,10 +37,14 @@ import contextlib
|
|
|
36
37
|
import json
|
|
37
38
|
import os
|
|
38
39
|
import re
|
|
40
|
+
import sqlite3
|
|
39
41
|
from dataclasses import dataclass
|
|
40
42
|
from pathlib import Path
|
|
41
43
|
from typing import Iterable, Iterator, Optional, Union
|
|
42
44
|
|
|
45
|
+
from claude_code_tools import codex_live_rollout
|
|
46
|
+
from claude_code_tools.codex_rollout_db import selected_rollout_path
|
|
47
|
+
|
|
43
48
|
_UUID = r"[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}"
|
|
44
49
|
_ROLLOUT_NAME = re.compile(
|
|
45
50
|
rf"^rollout-(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}-\d{{2}}-\d{{2}})-"
|
|
@@ -74,16 +79,18 @@ class CodexRolloutName:
|
|
|
74
79
|
thread_id: The session (thread) id.
|
|
75
80
|
rollout_id: The rollout id; equals ``thread_id`` for a base
|
|
76
81
|
file.
|
|
82
|
+
has_segment_suffix: Whether the filename includes a second UUID.
|
|
77
83
|
"""
|
|
78
84
|
|
|
79
85
|
timestamp: str
|
|
80
86
|
thread_id: str
|
|
81
87
|
rollout_id: str
|
|
88
|
+
has_segment_suffix: bool = False
|
|
82
89
|
|
|
83
90
|
@property
|
|
84
91
|
def is_segment(self) -> bool:
|
|
85
|
-
"""Whether this names a segment
|
|
86
|
-
return self.rollout_id != self.thread_id
|
|
92
|
+
"""Whether this names a segment, including a repeated UUID suffix."""
|
|
93
|
+
return self.has_segment_suffix or self.rollout_id != self.thread_id
|
|
87
94
|
|
|
88
95
|
|
|
89
96
|
@dataclass(frozen=True)
|
|
@@ -129,7 +136,7 @@ class CodexHistory:
|
|
|
129
136
|
the first turn): the session's base file then holds none of
|
|
130
137
|
the history, so readers must follow the chain, not the base.
|
|
131
138
|
"""
|
|
132
|
-
if len(self.links)
|
|
139
|
+
if len(self.links) != 1:
|
|
133
140
|
return True
|
|
134
141
|
name = parse_codex_rollout_name(self.links[0].path.name)
|
|
135
142
|
return name is not None and name.is_segment
|
|
@@ -159,6 +166,13 @@ class CodexHistory:
|
|
|
159
166
|
and base is not None
|
|
160
167
|
and base.thread_id == newest.thread_id
|
|
161
168
|
)
|
|
169
|
+
if not keep_base_meta:
|
|
170
|
+
# A reverted rollout's single-ID filename can change while its
|
|
171
|
+
# session_meta still identifies the base's stable thread.
|
|
172
|
+
owner = paginated_thread_id(self.newest_path)
|
|
173
|
+
keep_base_meta = owner is not None and owner == paginated_thread_id(
|
|
174
|
+
self.base_path
|
|
175
|
+
)
|
|
162
176
|
if not keep_base_meta:
|
|
163
177
|
# A paginated fork: the oldest links belong to the source
|
|
164
178
|
# thread, so the canonical meta is the newest rollout's.
|
|
@@ -190,8 +204,9 @@ def parse_codex_rollout_name(name: str) -> Optional[CodexRolloutName]:
|
|
|
190
204
|
timestamp, thread_id, rollout_id = match.groups()
|
|
191
205
|
return CodexRolloutName(
|
|
192
206
|
timestamp=timestamp,
|
|
193
|
-
thread_id=thread_id,
|
|
194
|
-
rollout_id=rollout_id or thread_id,
|
|
207
|
+
thread_id=thread_id.lower(),
|
|
208
|
+
rollout_id=(rollout_id or thread_id).lower(),
|
|
209
|
+
has_segment_suffix=rollout_id is not None,
|
|
195
210
|
)
|
|
196
211
|
|
|
197
212
|
|
|
@@ -266,7 +281,7 @@ def codex_thread_files(session_file: Union[str, Path]) -> list[Path]:
|
|
|
266
281
|
|
|
267
282
|
|
|
268
283
|
def resolve_codex_history(
|
|
269
|
-
session_file: Union[str, Path, CodexHistory],
|
|
284
|
+
session_file: Union[str, Path, CodexHistory], *, use_selected_rollout: bool = False
|
|
270
285
|
) -> CodexHistory:
|
|
271
286
|
"""Resolve the full, ordered history of a Codex session.
|
|
272
287
|
|
|
@@ -278,6 +293,8 @@ def resolve_codex_history(
|
|
|
278
293
|
Args:
|
|
279
294
|
session_file: A rollout file, or an already resolved history
|
|
280
295
|
(returned unchanged).
|
|
296
|
+
use_selected_rollout: For ports, follow the native thread selection.
|
|
297
|
+
File management retains its filesystem-based view of the chain.
|
|
281
298
|
|
|
282
299
|
Returns:
|
|
283
300
|
The resolved history.
|
|
@@ -294,21 +311,144 @@ def resolve_codex_history(
|
|
|
294
311
|
if parsed is None:
|
|
295
312
|
return CodexHistory((ChainLink(path, None),))
|
|
296
313
|
meta = _read_session_meta(path)
|
|
297
|
-
if not parsed.is_segment
|
|
314
|
+
if not (use_selected_rollout or parsed.is_segment or _is_paginated_meta(meta)):
|
|
298
315
|
return CodexHistory((ChainLink(path, None),))
|
|
299
316
|
|
|
317
|
+
with codex_listing_snapshot():
|
|
318
|
+
return _resolve_paginated(_absolute(path), parsed, meta, use_selected_rollout)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def paginated_thread_id(path: Path) -> str | None:
|
|
322
|
+
"""Read a paginated rollout's stable thread ID from its header."""
|
|
323
|
+
name = parse_codex_rollout_name(path.name)
|
|
324
|
+
meta = _read_session_meta(path)
|
|
325
|
+
if not ((name and name.is_segment) or _is_paginated_meta(meta)):
|
|
326
|
+
return None
|
|
327
|
+
return _metadata_thread_id(meta)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _metadata_thread_id(meta: dict | None) -> str | None:
|
|
331
|
+
"""Extract the stable thread UUID from a paginated header."""
|
|
332
|
+
if meta is None:
|
|
333
|
+
return None
|
|
334
|
+
owner = meta.get("id")
|
|
335
|
+
if not isinstance(owner, str) or not owner:
|
|
336
|
+
owner = meta.get("session_id")
|
|
337
|
+
if isinstance(owner, str) and re.fullmatch(_UUID, owner):
|
|
338
|
+
return owner.lower()
|
|
339
|
+
return None
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def _disk_leaf(roots: list[tuple[Path, bool]], thread_id: str) -> Path:
|
|
343
|
+
"""Recover a unique unindexed leaf, including single-ID revert filenames."""
|
|
344
|
+
files: dict[Path, str] = {}
|
|
345
|
+
parents: set[str] = set()
|
|
346
|
+
for root, recursive in roots:
|
|
347
|
+
for key, entries in _listing(root, recursive).items():
|
|
348
|
+
for path, name in entries:
|
|
349
|
+
# Each segment is indexed twice. Only visit its rollout-ID entry.
|
|
350
|
+
if name.rollout_id != key or not path.is_file():
|
|
351
|
+
continue
|
|
352
|
+
if name.is_segment and name.thread_id != thread_id:
|
|
353
|
+
continue
|
|
354
|
+
meta = _read_session_meta(path)
|
|
355
|
+
if not name.is_segment and meta and not _is_paginated_meta(meta):
|
|
356
|
+
continue
|
|
357
|
+
if _metadata_thread_id(meta) != thread_id:
|
|
358
|
+
if name.thread_id == thread_id and meta is None:
|
|
359
|
+
raise CodexHistoryChainError(
|
|
360
|
+
f"Unreadable rollout header: {path}"
|
|
361
|
+
)
|
|
362
|
+
continue
|
|
363
|
+
files[path] = name.rollout_id
|
|
364
|
+
base = _history_base(path, meta)
|
|
365
|
+
if base is not None:
|
|
366
|
+
parents.add(base[0])
|
|
367
|
+
leaves = [path for path, rollout_id in files.items() if rollout_id not in parents]
|
|
368
|
+
if len(leaves) != 1:
|
|
369
|
+
for parent in sorted(parents - set(files.values())):
|
|
370
|
+
if _find_rollout(roots, parent) is None:
|
|
371
|
+
raise CodexHistoryChainError(
|
|
372
|
+
f"Codex session history is incomplete: missing ancestor {parent}"
|
|
373
|
+
)
|
|
374
|
+
raise CodexHistoryChainError(
|
|
375
|
+
f"Cannot select a unique rollout for {thread_id}: {len(leaves)} leaves"
|
|
376
|
+
)
|
|
377
|
+
return leaves[0]
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def _selected_leaf(
|
|
381
|
+
roots: list[tuple[Path, bool]], thread_id: str, plain_fallback: Path | None
|
|
382
|
+
) -> Path:
|
|
383
|
+
"""Prefer native selection, then a plain file or a unique paginated chain."""
|
|
384
|
+
if roots[0][1]:
|
|
385
|
+
home = roots[0][0].parent
|
|
386
|
+
try:
|
|
387
|
+
selected = codex_live_rollout.live_rollout_path(home, thread_id)
|
|
388
|
+
if selected is None:
|
|
389
|
+
selected = selected_rollout_path(home, thread_id)
|
|
390
|
+
except sqlite3.Error:
|
|
391
|
+
# A damaged state database cannot identify a leaf. Port only a
|
|
392
|
+
# unique disk lineage, as for an unindexed paginated thread.
|
|
393
|
+
selected = None
|
|
394
|
+
except (OSError, ValueError) as error:
|
|
395
|
+
raise CodexHistoryChainError(
|
|
396
|
+
f"Cannot select Codex rollout for {thread_id}: {error}"
|
|
397
|
+
) from error
|
|
398
|
+
if selected is not None:
|
|
399
|
+
leaf = selected.resolve()
|
|
400
|
+
if not any(leaf.is_relative_to(root.resolve()) for root, _ in roots):
|
|
401
|
+
raise CodexHistoryChainError(
|
|
402
|
+
f"Selected rollout {selected} is outside Codex home {home}"
|
|
403
|
+
)
|
|
404
|
+
name = parse_codex_rollout_name(selected.name)
|
|
405
|
+
meta = _read_session_meta(selected)
|
|
406
|
+
# Plain legacy rollouts use filename identity: an inline fork
|
|
407
|
+
# can begin with its parent's header, or have no session_meta.
|
|
408
|
+
owner = None
|
|
409
|
+
if name is not None:
|
|
410
|
+
if name.is_segment or _is_paginated_meta(meta):
|
|
411
|
+
owner = _metadata_thread_id(meta)
|
|
412
|
+
if name.is_segment and name.thread_id != owner:
|
|
413
|
+
owner = None
|
|
414
|
+
else:
|
|
415
|
+
owner = name.thread_id
|
|
416
|
+
if owner != thread_id:
|
|
417
|
+
raise CodexHistoryChainError(
|
|
418
|
+
f"Selected rollout {selected} does not belong to {thread_id}"
|
|
419
|
+
)
|
|
420
|
+
return selected
|
|
421
|
+
if plain_fallback is not None:
|
|
422
|
+
return plain_fallback
|
|
423
|
+
return _disk_leaf(roots, thread_id)
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def _resolve_paginated(
|
|
427
|
+
path: Path, parsed: CodexRolloutName, meta: dict | None, use_selected_rollout: bool
|
|
428
|
+
) -> CodexHistory:
|
|
429
|
+
"""Walk the parent references from the requested leaf within one listing."""
|
|
300
430
|
roots = _search_roots(path)
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
431
|
+
thread_files = {}
|
|
432
|
+
if use_selected_rollout:
|
|
433
|
+
paginated = parsed.is_segment or _is_paginated_meta(meta)
|
|
434
|
+
header_id = _metadata_thread_id(meta) if paginated else None
|
|
435
|
+
if parsed.is_segment and header_id != parsed.thread_id:
|
|
436
|
+
raise CodexHistoryChainError(
|
|
437
|
+
f"Rollout {path} does not belong to its filename thread "
|
|
438
|
+
f"{parsed.thread_id}: header identifies {header_id!r}"
|
|
439
|
+
)
|
|
440
|
+
thread_id = header_id or parsed.thread_id
|
|
441
|
+
newest_path = _selected_leaf(roots, thread_id, None if paginated else path)
|
|
442
|
+
else:
|
|
443
|
+
# Prefer the supplied file to another copy with the same rollout ID.
|
|
444
|
+
thread_files[parsed.rollout_id] = (path, parsed)
|
|
445
|
+
for candidate, name in _iter_rollouts(roots, parsed.thread_id):
|
|
446
|
+
if name.thread_id == parsed.thread_id:
|
|
447
|
+
thread_files.setdefault(name.rollout_id, (candidate, name))
|
|
448
|
+
newest_path, _ = max(
|
|
449
|
+
thread_files.values(),
|
|
450
|
+
key=lambda item: (item[1].timestamp, item[1].rollout_id),
|
|
451
|
+
)
|
|
312
452
|
|
|
313
453
|
links = [ChainLink(newest_path, None)]
|
|
314
454
|
seen = {newest_path.resolve()}
|
|
@@ -333,7 +473,10 @@ def resolve_codex_history(
|
|
|
333
473
|
break
|
|
334
474
|
parent_id, offset = base
|
|
335
475
|
found = thread_files.get(parent_id)
|
|
336
|
-
|
|
476
|
+
if use_selected_rollout:
|
|
477
|
+
parent = _find_rollout(roots, parent_id, require_unique=True)
|
|
478
|
+
else:
|
|
479
|
+
parent = found[0] if found else _find_rollout(roots, parent_id)
|
|
337
480
|
if parent is None:
|
|
338
481
|
raise CodexHistoryChainError(
|
|
339
482
|
f"Codex session history is incomplete: rollout "
|
|
@@ -598,7 +741,7 @@ def _history_base(
|
|
|
598
741
|
raise CodexHistoryChainError(
|
|
599
742
|
f"Malformed history_base in {path}: {base!r}"
|
|
600
743
|
)
|
|
601
|
-
return parent_id, offset
|
|
744
|
+
return parent_id.lower(), offset
|
|
602
745
|
|
|
603
746
|
|
|
604
747
|
def _check_offset(parent: Path, offset: int, child: Path) -> None:
|
|
@@ -705,7 +848,7 @@ def _listing(
|
|
|
705
848
|
if parsed is None:
|
|
706
849
|
continue
|
|
707
850
|
by_id.setdefault(parsed.thread_id, []).append((candidate, parsed))
|
|
708
|
-
if parsed.
|
|
851
|
+
if parsed.thread_id != parsed.rollout_id:
|
|
709
852
|
by_id.setdefault(parsed.rollout_id, []).append((candidate, parsed))
|
|
710
853
|
if _snapshot is not None:
|
|
711
854
|
_snapshot[key] = by_id
|
|
@@ -724,14 +867,20 @@ def _iter_rollouts(
|
|
|
724
867
|
|
|
725
868
|
|
|
726
869
|
def _find_rollout(
|
|
727
|
-
roots: Iterable[tuple[Path, bool]], rollout_id: str
|
|
870
|
+
roots: Iterable[tuple[Path, bool]], rollout_id: str, *, require_unique: bool = False
|
|
728
871
|
) -> Optional[Path]:
|
|
729
872
|
"""Find the rollout file with a given rollout id, if any.
|
|
730
873
|
|
|
731
874
|
A rollout id may belong to another thread (a paginated fork
|
|
732
875
|
inherits its source thread's history).
|
|
733
876
|
"""
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
877
|
+
matches = (
|
|
878
|
+
path for path, name in _iter_rollouts(roots, rollout_id)
|
|
879
|
+
if name.rollout_id == rollout_id
|
|
880
|
+
)
|
|
881
|
+
first = next(matches, None)
|
|
882
|
+
if require_unique and (other := next(matches, None)) is not None:
|
|
883
|
+
raise CodexHistoryChainError(
|
|
884
|
+
f"Ambiguous ancestor rollout {rollout_id}: {first} and {other}"
|
|
885
|
+
)
|
|
886
|
+
return first
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Identify the rollout held open by a native Codex thread writer."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import struct
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _locked(path: Path) -> bool:
|
|
11
|
+
"""Check an existing native advisory lock without creating a lock file."""
|
|
12
|
+
try:
|
|
13
|
+
with path.open("rb") as lock:
|
|
14
|
+
if sys.platform == "win32":
|
|
15
|
+
import msvcrt
|
|
16
|
+
|
|
17
|
+
# Codex locks the entire file, including byte zero of an
|
|
18
|
+
# empty lock file. Probe only that byte on our read handle.
|
|
19
|
+
try:
|
|
20
|
+
msvcrt.locking(lock.fileno(), msvcrt.LK_NBLCK, 1)
|
|
21
|
+
except PermissionError as exc:
|
|
22
|
+
raise ValueError(
|
|
23
|
+
"Active Codex writer on Windows: close the Codex session, "
|
|
24
|
+
"then port again."
|
|
25
|
+
) from exc
|
|
26
|
+
msvcrt.locking(lock.fileno(), msvcrt.LK_UNLCK, 1)
|
|
27
|
+
return False
|
|
28
|
+
import fcntl
|
|
29
|
+
|
|
30
|
+
if sys.platform == "darwin":
|
|
31
|
+
# Darwin F_GETLK reports a conflicting flock without taking
|
|
32
|
+
# a transient shared lock that could deny a new Codex writer.
|
|
33
|
+
flock = struct.Struct("qqihh") # Darwin struct flock
|
|
34
|
+
probe = flock.pack(0, 0, 0, fcntl.F_RDLCK, os.SEEK_SET)
|
|
35
|
+
result = fcntl.fcntl(lock, fcntl.F_GETLK, probe)
|
|
36
|
+
return flock.unpack(result)[3] != fcntl.F_UNLCK
|
|
37
|
+
try:
|
|
38
|
+
fcntl.flock(lock, fcntl.LOCK_SH | fcntl.LOCK_NB)
|
|
39
|
+
except BlockingIOError:
|
|
40
|
+
return True
|
|
41
|
+
except FileNotFoundError:
|
|
42
|
+
return False
|
|
43
|
+
except (ImportError, OSError) as exc:
|
|
44
|
+
raise ValueError(f"Cannot check native writer lock {path}: {exc}") from exc
|
|
45
|
+
return False
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _lsof(*args: str) -> bytes:
|
|
49
|
+
"""Run a file- or PID-scoped descriptor query, failing closed on errors."""
|
|
50
|
+
try:
|
|
51
|
+
return subprocess.run(
|
|
52
|
+
["lsof", "-nP", *args],
|
|
53
|
+
capture_output=True,
|
|
54
|
+
timeout=15,
|
|
55
|
+
check=True,
|
|
56
|
+
).stdout
|
|
57
|
+
except (OSError, subprocess.SubprocessError) as exc:
|
|
58
|
+
raise ValueError(f"Cannot inspect the active Codex writer: {exc}") from exc
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def live_rollout_path(home: Path, thread_id: str) -> Path | None:
|
|
62
|
+
"""Find the writable rollout of a locked thread, or None for an idle thread."""
|
|
63
|
+
from claude_code_tools.codex_history_chain import (
|
|
64
|
+
_read_session_meta,
|
|
65
|
+
parse_codex_rollout_name,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
lock = home / "thread-writer-locks" / f"{thread_id.lower()}.lock"
|
|
69
|
+
if not _locked(lock):
|
|
70
|
+
return None
|
|
71
|
+
# An open lock descriptor need not own the lock. With multiple holders we
|
|
72
|
+
# cannot identify the owner portably (Darwin hides flock ownership).
|
|
73
|
+
holders = set(_lsof("-t", "--", str(lock.absolute())).splitlines())
|
|
74
|
+
if len(holders) != 1 or not next(iter(holders)).isdigit():
|
|
75
|
+
raise ValueError(f"Cannot identify the active Codex writer for {thread_id}")
|
|
76
|
+
pid = holders.pop().decode("ascii")
|
|
77
|
+
roots = [home.absolute() / d for d in ("sessions", "archived_sessions")]
|
|
78
|
+
resolved_roots = [(root.resolve(), root) for root in roots]
|
|
79
|
+
matches = set()
|
|
80
|
+
lock_path = lock.resolve()
|
|
81
|
+
saw_lock = False
|
|
82
|
+
# NUL-terminated fields preserve whitespace in filenames. The p record
|
|
83
|
+
# starts the listing, then each f record describes one descriptor.
|
|
84
|
+
for record in _lsof("-p", pid, "-F0afDin").split(b"\0\n"):
|
|
85
|
+
if not record.startswith(b"f"):
|
|
86
|
+
continue
|
|
87
|
+
fields = {item[:1]: item[1:] for item in record.split(b"\0")}
|
|
88
|
+
name = Path(os.fsdecode(fields.get(b"n", b"")))
|
|
89
|
+
if not name.is_absolute():
|
|
90
|
+
continue
|
|
91
|
+
if name == lock_path:
|
|
92
|
+
saw_lock = True
|
|
93
|
+
if fields.get(b"a") not in (b"w", b"u"):
|
|
94
|
+
continue
|
|
95
|
+
if not parse_codex_rollout_name(name.name):
|
|
96
|
+
continue
|
|
97
|
+
for physical, logical in resolved_roots:
|
|
98
|
+
if not name.is_relative_to(physical):
|
|
99
|
+
continue
|
|
100
|
+
path = logical / name.relative_to(physical)
|
|
101
|
+
try:
|
|
102
|
+
st = path.stat()
|
|
103
|
+
identity = (int(fields[b"D"], 16), int(fields[b"i"]))
|
|
104
|
+
if (st.st_dev, st.st_ino) != identity:
|
|
105
|
+
raise ValueError("descriptor no longer identifies the file")
|
|
106
|
+
meta = _read_session_meta(path) or {}
|
|
107
|
+
owner = meta.get("id") or meta.get("session_id")
|
|
108
|
+
if not isinstance(owner, str) or not owner:
|
|
109
|
+
raise ValueError("missing thread id")
|
|
110
|
+
except (OSError, KeyError, ValueError) as exc:
|
|
111
|
+
raise ValueError(
|
|
112
|
+
f"Cannot identify writable rollout {path}: {exc}"
|
|
113
|
+
) from exc
|
|
114
|
+
if owner.lower() == thread_id.lower():
|
|
115
|
+
matches.add(path)
|
|
116
|
+
break
|
|
117
|
+
if not saw_lock or len(matches) != 1:
|
|
118
|
+
raise ValueError(
|
|
119
|
+
f"Cannot select the active rollout for {thread_id}: "
|
|
120
|
+
f"writer lock observed={saw_lock}, "
|
|
121
|
+
f"matching writable rollouts={len(matches)}"
|
|
122
|
+
)
|
|
123
|
+
return matches.pop()
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Locate Codex's selected rollout in its local SQLite state."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
import sqlite3
|
|
7
|
+
from contextlib import closing
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def codex_state_database(home: Path) -> Path | None:
|
|
12
|
+
"""Return the highest-numbered Codex state database, if present."""
|
|
13
|
+
candidates: list[tuple[int, Path]] = []
|
|
14
|
+
for path in home.glob("state_*.sqlite"):
|
|
15
|
+
match = re.fullmatch(r"state_(\d+)\.sqlite", path.name)
|
|
16
|
+
if match and path.is_file():
|
|
17
|
+
candidates.append((int(match.group(1)), path))
|
|
18
|
+
return max(candidates)[1] if candidates else None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def codex_rollout_path(raw_path: object, home: Path) -> Path | None:
|
|
22
|
+
"""Normalize a rollout path read from the Codex database."""
|
|
23
|
+
if not isinstance(raw_path, str) or not raw_path.strip():
|
|
24
|
+
return None
|
|
25
|
+
try:
|
|
26
|
+
path = Path(raw_path).expanduser()
|
|
27
|
+
if not path.is_absolute():
|
|
28
|
+
path = home / path
|
|
29
|
+
return path.resolve(strict=False)
|
|
30
|
+
except (OSError, RuntimeError, TypeError, ValueError):
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def selected_rollout_path(home: Path, thread_id: str) -> Path | None:
|
|
35
|
+
"""Return the path in the thread row, or None for an unindexed thread."""
|
|
36
|
+
database = codex_state_database(home)
|
|
37
|
+
if database is None:
|
|
38
|
+
return None
|
|
39
|
+
uri = database.absolute().as_uri() + "?mode=ro"
|
|
40
|
+
with closing(sqlite3.connect(uri, uri=True)) as connection:
|
|
41
|
+
row = connection.execute(
|
|
42
|
+
"SELECT rollout_path FROM threads WHERE id = ?",
|
|
43
|
+
(thread_id,),
|
|
44
|
+
).fetchone()
|
|
45
|
+
if row is None:
|
|
46
|
+
# The native UUID spelling hits the primary key. Older rows can
|
|
47
|
+
# use a different case, so pay for a case-insensitive scan on miss.
|
|
48
|
+
row = connection.execute(
|
|
49
|
+
"SELECT rollout_path FROM threads WHERE id = ? COLLATE NOCASE",
|
|
50
|
+
(thread_id,),
|
|
51
|
+
).fetchone()
|
|
52
|
+
if row is None:
|
|
53
|
+
return None
|
|
54
|
+
selected = codex_rollout_path(row[0], home)
|
|
55
|
+
if selected is None or not selected.is_file():
|
|
56
|
+
raise ValueError(
|
|
57
|
+
f"Missing or invalid selected rollout for {thread_id}: {row[0]}"
|
|
58
|
+
)
|
|
59
|
+
return selected
|
{claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/find_claude_session.py
RENAMED
|
@@ -21,8 +21,6 @@ import re
|
|
|
21
21
|
import shlex
|
|
22
22
|
import sys
|
|
23
23
|
import time
|
|
24
|
-
import termios
|
|
25
|
-
import tty
|
|
26
24
|
from datetime import datetime
|
|
27
25
|
from pathlib import Path
|
|
28
26
|
from typing import List, Set, Tuple, Optional
|
|
@@ -76,6 +74,8 @@ def get_session_start_timestamp(jsonl_file: Path) -> Optional[float]:
|
|
|
76
74
|
|
|
77
75
|
def _read_key() -> str:
|
|
78
76
|
"""Read a single keypress (Enter/Esc)."""
|
|
77
|
+
import termios
|
|
78
|
+
import tty
|
|
79
79
|
fd = sys.stdin.fileno()
|
|
80
80
|
old = termios.tcgetattr(fd)
|
|
81
81
|
try:
|
{claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/find_codex_session.py
RENAMED
|
@@ -21,8 +21,6 @@ import re
|
|
|
21
21
|
import shlex
|
|
22
22
|
import sys
|
|
23
23
|
import time
|
|
24
|
-
import termios
|
|
25
|
-
import tty
|
|
26
24
|
from datetime import datetime
|
|
27
25
|
from pathlib import Path
|
|
28
26
|
from typing import Optional, Tuple
|
|
@@ -47,6 +45,8 @@ from claude_code_tools.codex_history_chain import (
|
|
|
47
45
|
|
|
48
46
|
def _read_key() -> str:
|
|
49
47
|
"""Read a single keypress (Enter/Esc)."""
|
|
48
|
+
import termios
|
|
49
|
+
import tty
|
|
50
50
|
fd = sys.stdin.fileno()
|
|
51
51
|
old = termios.tcgetattr(fd)
|
|
52
52
|
try:
|
{claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/port_codex_provider.py
RENAMED
|
@@ -40,11 +40,6 @@ from claude_code_tools.codex_history_chain import (
|
|
|
40
40
|
CodexHistory,
|
|
41
41
|
resolve_codex_history,
|
|
42
42
|
)
|
|
43
|
-
from claude_code_tools.port_claude_to_codex import (
|
|
44
|
-
_append_history_transactional,
|
|
45
|
-
_new_codex_session_id,
|
|
46
|
-
_utc_now_codex_timestamp,
|
|
47
|
-
)
|
|
48
43
|
from claude_code_tools.port_codex_to_claude import _write_transcript_atomic
|
|
49
44
|
from claude_code_tools.session_utils import get_codex_home
|
|
50
45
|
|
|
@@ -185,7 +180,7 @@ def _retarget_lines(
|
|
|
185
180
|
"model_provider": provider,
|
|
186
181
|
}
|
|
187
182
|
if first:
|
|
188
|
-
old_id = payload.get("id")
|
|
183
|
+
old_id = payload.get("id") or payload.get("session_id")
|
|
189
184
|
payload.update(id=new_id, session_id=new_id,
|
|
190
185
|
timestamp=now_iso, forked_from_id=old_id)
|
|
191
186
|
record = {
|
|
@@ -263,8 +258,8 @@ def retarget_codex_session(
|
|
|
263
258
|
source = Path(rollout_file).expanduser()
|
|
264
259
|
if not source.is_file():
|
|
265
260
|
raise FileNotFoundError(f"Codex session not found: {source}")
|
|
266
|
-
|
|
267
|
-
|
|
261
|
+
history = resolve_codex_history(source, use_selected_rollout=True)
|
|
262
|
+
meta = _read_session_meta(history.newest_path)
|
|
268
263
|
source_provider = str(meta.get("model_provider") or "openai")
|
|
269
264
|
if source_provider == provider:
|
|
270
265
|
raise ValueError(
|
|
@@ -275,6 +270,14 @@ def retarget_codex_session(
|
|
|
275
270
|
home_dir = get_codex_home(str(codex_home))
|
|
276
271
|
else:
|
|
277
272
|
home_dir = _codex_home_of(source.absolute()) or get_codex_home(None)
|
|
273
|
+
# Output helpers need POSIX locking. Check the source writer first so a
|
|
274
|
+
# Windows lock conflict can report the retry instruction.
|
|
275
|
+
from claude_code_tools.port_claude_to_codex import (
|
|
276
|
+
_append_history_transactional,
|
|
277
|
+
_new_codex_session_id,
|
|
278
|
+
_utc_now_codex_timestamp,
|
|
279
|
+
)
|
|
280
|
+
|
|
278
281
|
new_id = _new_codex_session_id()
|
|
279
282
|
now_iso = _utc_now_codex_timestamp()
|
|
280
283
|
now_local = datetime.datetime.now()
|
|
@@ -287,7 +290,7 @@ def retarget_codex_session(
|
|
|
287
290
|
preview: dict[str, Optional[str]] = {"text": None}
|
|
288
291
|
_write_transcript_atomic(
|
|
289
292
|
out_path,
|
|
290
|
-
_retarget_lines(
|
|
293
|
+
_retarget_lines(history.newest_path, history, provider=provider, new_id=new_id,
|
|
291
294
|
now_iso=now_iso, stats=stats, preview=preview),
|
|
292
295
|
)
|
|
293
296
|
_append_history_transactional(
|
{claude_code_tools-1.32.2 → claude_code_tools-1.32.3}/claude_code_tools/port_codex_to_claude.py
RENAMED
|
@@ -274,7 +274,7 @@ def harvest_rollout_meta(
|
|
|
274
274
|
Dict with ``cwd``, ``branch``, ``source_id`` and ``timestamp``
|
|
275
275
|
keys (values may be None when unavailable).
|
|
276
276
|
"""
|
|
277
|
-
history = resolve_codex_history(codex_session_file)
|
|
277
|
+
history = resolve_codex_history(codex_session_file, use_selected_rollout=True)
|
|
278
278
|
file_uuid = get_session_uuid(history.newest_path.stem)
|
|
279
279
|
meta: dict[str, Any] = {
|
|
280
280
|
"cwd": None,
|
|
@@ -292,7 +292,10 @@ def harvest_rollout_meta(
|
|
|
292
292
|
payload = data.get("payload")
|
|
293
293
|
if not isinstance(payload, dict):
|
|
294
294
|
continue
|
|
295
|
-
|
|
295
|
+
header_id = _session_meta_id(payload)
|
|
296
|
+
is_file_meta = header_id is not None and (
|
|
297
|
+
header_id.casefold() == file_uuid.casefold()
|
|
298
|
+
)
|
|
296
299
|
if is_file_meta and not meta_authoritative:
|
|
297
300
|
for key in meta:
|
|
298
301
|
meta[key] = None
|
|
@@ -571,7 +574,7 @@ def iter_flat_messages(
|
|
|
571
574
|
"""
|
|
572
575
|
# Resolve a paginated chain once so both passes read the same
|
|
573
576
|
# files even if Codex starts a new segment in between.
|
|
574
|
-
history = resolve_codex_history(codex_session_file)
|
|
577
|
+
history = resolve_codex_history(codex_session_file, use_selected_rollout=True)
|
|
575
578
|
boundary, goal, total = _scan_rollout(history)
|
|
576
579
|
for idx, data in enumerate(_iter_rollout_records(history)):
|
|
577
580
|
if idx >= total:
|
|
@@ -822,7 +825,7 @@ def port_codex_session_to_claude(
|
|
|
822
825
|
# One resolution for every pass: a paginated session's history
|
|
823
826
|
# spans several rollout files, and a broken chain raises
|
|
824
827
|
# CodexHistoryChainError rather than porting a partial history.
|
|
825
|
-
history = resolve_codex_history(codex_path)
|
|
828
|
+
history = resolve_codex_history(codex_path, use_selected_rollout=True)
|
|
826
829
|
meta = harvest_rollout_meta(history)
|
|
827
830
|
source_id = meta["source_id"] or get_session_uuid(codex_path.stem)
|
|
828
831
|
transcript = merge_and_alternate(
|