python-codex 0.4.0__tar.gz → 0.4.1__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 (91) hide show
  1. {python_codex-0.4.0 → python_codex-0.4.1}/PKG-INFO +14 -10
  2. {python_codex-0.4.0 → python_codex-0.4.1}/README.md +13 -9
  3. {python_codex-0.4.0 → python_codex-0.4.1}/README_ZH.md +7 -4
  4. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/runtime.py +1 -1
  5. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/async_bridge.py +3 -4
  6. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/session_persist.py +28 -0
  7. {python_codex-0.4.0 → python_codex-0.4.1}/pyproject.toml +2 -2
  8. {python_codex-0.4.0 → python_codex-0.4.1}/.gitignore +0 -0
  9. {python_codex-0.4.0 → python_codex-0.4.1}/LICENSE +0 -0
  10. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/__init__.py +0 -0
  11. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/__main__.py +0 -0
  12. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/agent.py +0 -0
  13. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/bootstrap.py +0 -0
  14. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/cli.py +0 -0
  15. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/context.py +0 -0
  16. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/events.py +0 -0
  17. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/model.py +0 -0
  18. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/portable/__init__.py +0 -0
  19. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/portable/client.py +0 -0
  20. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/portable/server.py +0 -0
  21. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/default_base_instructions.md +0 -0
  22. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/models.json +0 -0
  23. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/permissions/approval_policy/never.md +0 -0
  24. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/permissions/approval_policy/on_failure.md +0 -0
  25. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/permissions/approval_policy/on_request.md +0 -0
  26. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/permissions/approval_policy/on_request_rule_request_permission.md +0 -0
  27. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/permissions/approval_policy/unless_trusted.md +0 -0
  28. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/permissions/sandbox_mode/danger_full_access.md +0 -0
  29. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/permissions/sandbox_mode/read_only.md +0 -0
  30. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/prompts/permissions/sandbox_mode/workspace_write.md +0 -0
  31. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/protocol.py +0 -0
  32. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/__init__.py +0 -0
  33. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/agent_tool_schemas.py +0 -0
  34. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/apply_patch_tool.py +0 -0
  35. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/base_tool.py +0 -0
  36. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/clock_tool.py +0 -0
  37. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/close_agent_tool.py +0 -0
  38. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/code_mode_manager.py +0 -0
  39. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/exec_command_tool.py +0 -0
  40. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/exec_runtime.js +0 -0
  41. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/exec_tool.py +0 -0
  42. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/grep_files_tool.py +0 -0
  43. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/list_dir_tool.py +0 -0
  44. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/read_file_tool.py +0 -0
  45. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/request_permissions_tool.py +0 -0
  46. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/request_user_input_tool.py +0 -0
  47. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/resume_agent_tool.py +0 -0
  48. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/runtime_services.py +0 -0
  49. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/send_input_tool.py +0 -0
  50. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/shell_command_tool.py +0 -0
  51. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/shell_tool.py +0 -0
  52. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/spawn_agent_tool.py +0 -0
  53. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/unified_exec_manager.py +0 -0
  54. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/update_plan_tool.py +0 -0
  55. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/view_image_tool.py +0 -0
  56. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/wait_agent_tool.py +0 -0
  57. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/wait_tool.py +0 -0
  58. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/web_search_tool.py +0 -0
  59. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/tools/write_stdin_tool.py +0 -0
  60. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/__init__.py +0 -0
  61. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/_aes_gcm/LICENSE +0 -0
  62. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/_aes_gcm/README.md +0 -0
  63. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/_aes_gcm/__init__.py +0 -0
  64. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/_aes_gcm/aes.py +0 -0
  65. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/_aes_gcm/gcm.py +0 -0
  66. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/_aes_gcm/source-sha256.json +0 -0
  67. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/compactor.py +0 -0
  68. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/compat.py +0 -0
  69. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/crypto.py +0 -0
  70. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/debug.py +0 -0
  71. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/doctor.py +0 -0
  72. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/dotenv.py +0 -0
  73. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/event_helpers.py +0 -0
  74. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/get_env.py +0 -0
  75. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/image_utils.py +0 -0
  76. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/model_metadata.py +0 -0
  77. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/random_ids.py +0 -0
  78. {python_codex-0.4.0 → python_codex-0.4.1}/pycodex/utils/truncation.py +0 -0
  79. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/__init__.py +0 -0
  80. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/__main__.py +0 -0
  81. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/app.py +0 -0
  82. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/config.py +0 -0
  83. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/messages_api.py +0 -0
  84. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/payload_processors.py +0 -0
  85. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/server.py +0 -0
  86. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/session_store.py +0 -0
  87. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/stream_router.py +0 -0
  88. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/tools/__init__.py +0 -0
  89. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/tools/custom_adapter.py +0 -0
  90. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/tools/web_search.py +0 -0
  91. {python_codex-0.4.0 → python_codex-0.4.1}/responses_server/trajectory_dump.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-codex
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: A minimal Python extraction of Codex's main agent loop
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.6.2
@@ -40,10 +40,14 @@ The import path remains `pycodex`; the CLI commands are `pycodex` and
40
40
 
41
41
  `python-codex` contains the Agent, runtime, CLI, standard tools, Responses
42
42
  compatibility server and portable storage support. `pycodex-ws` depends on the
43
- exact matching core version and contains the browser workspace, viewer assets,
44
- Feishu and IPython integrations, including their dependencies. It owns the
43
+ exact matching core version and contains the browser workspace, viewer assets
44
+ and optional Feishu integration. It owns the
45
45
  `workspace_server` and `pycodex_ws` modules and the `pycodex-ws` command.
46
46
 
47
+ The Feishu SDK is not installed automatically. Install it in the workspace's
48
+ Python environment with `python3 -m pip install lark-oapi` to enable `/link`.
49
+ If `lark_oapi` cannot be imported, `/link` reports that it is unavailable.
50
+
47
51
  Core does not require Pillow. Without it, `view_image` sends the original image
48
52
  bytes with `detail="original"`, including when `high` is requested. With Pillow
49
53
  installed, the default path retains resizing to a maximum dimension of 2048.
@@ -78,7 +82,7 @@ Relevant Rust reference points:
78
82
 
79
83
  ## Quick Start
80
84
 
81
- Install the core CLI, or install the workspace package to include all integrations:
85
+ Install the core CLI, or install the workspace package for the browser frontend:
82
86
 
83
87
  ```bash
84
88
  python3 -m pip install python-codex
@@ -86,7 +90,7 @@ python3 -m pip install pycodex-ws
86
90
  ```
87
91
 
88
92
  The core supports Python 3.6.2 or newer. The workspace package requires Python
89
- 3.7 or newer because of its Feishu SDK dependency. Commands are installed into
93
+ 3.7 or newer. Commands are installed into
90
94
  that interpreter's scripts directory. On a machine with multiple Python
91
95
  installations, select the same interpreter explicitly for startup:
92
96
 
@@ -118,7 +122,7 @@ uv run pycodex
118
122
 
119
123
  Tests are split by package. `uv run --dev pytest` runs both suites;
120
124
  `uv run --dev pytest packages/pycodex-ws/tests` runs workspace and integration
121
- tests. To check core without installing workspace or its SDKs, use a separate
125
+ tests. To check core without installing workspace, use a separate
122
126
  environment:
123
127
 
124
128
  ```bash
@@ -202,7 +206,7 @@ Supporting services live in `tools/`, `portable/` and `utils/`.
202
206
  - `pycodex/utils/image_utils.py`: image loading, resizing and data-URL preparation
203
207
  - `pycodex/prompts/`: vendored prompts and model metadata
204
208
  - `packages/pycodex-ws/workspace_server/`: Web board, API and file/diff viewers
205
- - `packages/pycodex-ws/pycodex_ws/`: Feishu, IPython and workspace assembly
209
+ - `packages/pycodex-ws/pycodex_ws/`: Feishu and workspace assembly
206
210
  - `packages/pycodex-ws/extensions/vscode/`: workspace's VS Code frontend, built separately as a VSIX
207
211
  - `tests/`: core tests
208
212
  - `packages/pycodex-ws/tests/`: workspace and cross-frontend integration tests
@@ -414,7 +418,8 @@ Current behavior:
414
418
  user instruction; this is intended for side-effect follow-ups such as
415
419
  Feishu notifications
416
420
  - `/link <feishu-email|open_id|chat_id>` in a workspace session attaches it
417
- to a Feishu card; multiple sessions in the same workspace process share
421
+ to a Feishu card when the optional `lark-oapi` SDK can be imported;
422
+ multiple sessions in the same workspace process share
418
423
  one Feishu long-connection listener and route card actions by message id
419
424
  - Feishu user OAuth stores its refresh token only in
420
425
  `~/.codex/.feishu_refresh_token` (mode `0600`). Run
@@ -735,8 +740,7 @@ CLI, Web and Feishu all use `AgentRuntime.submit_input`: not just `/model`
735
740
  and `/resume`, but every session command, steer/queue admission, interactive
736
741
  questions and permissions, state notifications and shutdown. Frontends only
737
742
  adapt input and render events. Web no longer imports or runs the CLI shell.
738
- IPython is the deliberate exception: `pycodex_ws.ipython.ipython_agent()` returns
739
- a bare Agent. Workspace assembly uses `pycodex_ws.build_runtime()` to add
743
+ Workspace assembly uses `pycodex_ws.build_runtime()` to add
740
744
  `/link` and `/unlink`; `pycodex.bootstrap.build_runtime()` provides core commands.
741
745
 
742
746
  ```python
@@ -20,10 +20,14 @@ The import path remains `pycodex`; the CLI commands are `pycodex` and
20
20
 
21
21
  `python-codex` contains the Agent, runtime, CLI, standard tools, Responses
22
22
  compatibility server and portable storage support. `pycodex-ws` depends on the
23
- exact matching core version and contains the browser workspace, viewer assets,
24
- Feishu and IPython integrations, including their dependencies. It owns the
23
+ exact matching core version and contains the browser workspace, viewer assets
24
+ and optional Feishu integration. It owns the
25
25
  `workspace_server` and `pycodex_ws` modules and the `pycodex-ws` command.
26
26
 
27
+ The Feishu SDK is not installed automatically. Install it in the workspace's
28
+ Python environment with `python3 -m pip install lark-oapi` to enable `/link`.
29
+ If `lark_oapi` cannot be imported, `/link` reports that it is unavailable.
30
+
27
31
  Core does not require Pillow. Without it, `view_image` sends the original image
28
32
  bytes with `detail="original"`, including when `high` is requested. With Pillow
29
33
  installed, the default path retains resizing to a maximum dimension of 2048.
@@ -58,7 +62,7 @@ Relevant Rust reference points:
58
62
 
59
63
  ## Quick Start
60
64
 
61
- Install the core CLI, or install the workspace package to include all integrations:
65
+ Install the core CLI, or install the workspace package for the browser frontend:
62
66
 
63
67
  ```bash
64
68
  python3 -m pip install python-codex
@@ -66,7 +70,7 @@ python3 -m pip install pycodex-ws
66
70
  ```
67
71
 
68
72
  The core supports Python 3.6.2 or newer. The workspace package requires Python
69
- 3.7 or newer because of its Feishu SDK dependency. Commands are installed into
73
+ 3.7 or newer. Commands are installed into
70
74
  that interpreter's scripts directory. On a machine with multiple Python
71
75
  installations, select the same interpreter explicitly for startup:
72
76
 
@@ -98,7 +102,7 @@ uv run pycodex
98
102
 
99
103
  Tests are split by package. `uv run --dev pytest` runs both suites;
100
104
  `uv run --dev pytest packages/pycodex-ws/tests` runs workspace and integration
101
- tests. To check core without installing workspace or its SDKs, use a separate
105
+ tests. To check core without installing workspace, use a separate
102
106
  environment:
103
107
 
104
108
  ```bash
@@ -182,7 +186,7 @@ Supporting services live in `tools/`, `portable/` and `utils/`.
182
186
  - `pycodex/utils/image_utils.py`: image loading, resizing and data-URL preparation
183
187
  - `pycodex/prompts/`: vendored prompts and model metadata
184
188
  - `packages/pycodex-ws/workspace_server/`: Web board, API and file/diff viewers
185
- - `packages/pycodex-ws/pycodex_ws/`: Feishu, IPython and workspace assembly
189
+ - `packages/pycodex-ws/pycodex_ws/`: Feishu and workspace assembly
186
190
  - `packages/pycodex-ws/extensions/vscode/`: workspace's VS Code frontend, built separately as a VSIX
187
191
  - `tests/`: core tests
188
192
  - `packages/pycodex-ws/tests/`: workspace and cross-frontend integration tests
@@ -394,7 +398,8 @@ Current behavior:
394
398
  user instruction; this is intended for side-effect follow-ups such as
395
399
  Feishu notifications
396
400
  - `/link <feishu-email|open_id|chat_id>` in a workspace session attaches it
397
- to a Feishu card; multiple sessions in the same workspace process share
401
+ to a Feishu card when the optional `lark-oapi` SDK can be imported;
402
+ multiple sessions in the same workspace process share
398
403
  one Feishu long-connection listener and route card actions by message id
399
404
  - Feishu user OAuth stores its refresh token only in
400
405
  `~/.codex/.feishu_refresh_token` (mode `0600`). Run
@@ -715,8 +720,7 @@ CLI, Web and Feishu all use `AgentRuntime.submit_input`: not just `/model`
715
720
  and `/resume`, but every session command, steer/queue admission, interactive
716
721
  questions and permissions, state notifications and shutdown. Frontends only
717
722
  adapt input and render events. Web no longer imports or runs the CLI shell.
718
- IPython is the deliberate exception: `pycodex_ws.ipython.ipython_agent()` returns
719
- a bare Agent. Workspace assembly uses `pycodex_ws.build_runtime()` to add
723
+ Workspace assembly uses `pycodex_ws.build_runtime()` to add
720
724
  `/link` and `/unlink`; `pycodex.bootstrap.build_runtime()` provides core commands.
721
725
 
722
726
  ```python
@@ -19,9 +19,13 @@ Import 路径仍保持 `pycodex`;CLI 命令为 `pycodex` 和 `pycodex-ws`。
19
19
 
20
20
  `python-codex` 提供 Agent、Runtime、CLI、标准工具、Responses 兼容服务和
21
21
  整套 portable 功能。`pycodex-ws` 精确依赖同版本的核心包,提供 Web 看板、
22
- viewer 资源、飞书和 IPython 集成及其依赖;它独立拥有 `workspace_server`、
22
+ viewer 资源和可选飞书集成;它独立拥有 `workspace_server`、
23
23
  `pycodex_ws` 模块和 `pycodex-ws` 命令。
24
24
 
25
+ 飞书 SDK 不会自动安装。需要 `/link` 时,在 workspace 使用的 Python 环境中
26
+ 手动执行 `python3 -m pip install lark-oapi`。如果无法导入 `lark_oapi`,
27
+ `/link` 只提示不可用,其他 workspace 功能照常使用。
28
+
25
29
  核心包不依赖 Pillow。未安装时,`view_image` 直接发送原图并返回
26
30
  `detail="original"`,省略 `detail` 或指定 `high` 也一样;已安装时默认仍将
27
31
  最长边缩至不超过 2048。`pycodex-ws` 为图片预览校验直接依赖 Pillow。
@@ -58,7 +62,7 @@ python3 -m pip install python-codex
58
62
  python3 -m pip install pycodex-ws
59
63
  ```
60
64
 
61
- 核心包要求 Python 3.6.2 或更新版本;workspace 包因飞书 SDK 要求 Python 3.7+。
65
+ 核心包要求 Python 3.6.2 或更新版本;workspace 包要求 Python 3.7+。
62
66
  命令会安装到该解释器的 scripts 目录。
63
67
  在同时存在 Python 2/3 或多套 Python 的机器上,可以明确使用安装时的解释器启动:
64
68
 
@@ -141,7 +145,7 @@ core 测试支持 Python 3.6.2+,workspace 测试要求 Python 3.7+;
141
145
  - `pycodex/utils/image_utils.py`:图片加载、缩放和 data URL 转换
142
146
  - `pycodex/prompts/`:内置提示和模型元数据
143
147
  - `packages/pycodex-ws/workspace_server/`:Web 看板、API、文件/diff 查看器
144
- - `packages/pycodex-ws/pycodex_ws/`:飞书、IPython 与 workspace 装配
148
+ - `packages/pycodex-ws/pycodex_ws/`:飞书与 workspace 装配
145
149
  - `packages/pycodex-ws/extensions/vscode/`:属于 workspace 的 VS Code 前端,独立构建 VSIX
146
150
  - `tests/`:core 测试
147
151
  - `packages/pycodex-ws/tests/`:workspace 与跨前端集成测试
@@ -154,7 +158,6 @@ core 测试支持 Python 3.6.2+,workspace 测试要求 Python 3.7+;
154
158
  所有会话命令、steer/queue 策略、模型/历史/标题状态、交互问答和权限响应、
155
159
  worker 启停及连接清理都由后端统一处理,前端只做输入和展示适配。
156
160
  Web 不再导入或运行 CLI shell,飞书运行中也能提交 steer 和回答问题。
157
- IPython 是明确的例外:`pycodex_ws.ipython.ipython_agent()` 返回裸 Agent。
158
161
  Workspace 使用 `pycodex_ws.build_runtime()` 装配 `/link`、`/unlink`;
159
162
  `pycodex.bootstrap.build_runtime()` 仅装配核心会话命令。
160
163
 
@@ -307,7 +307,7 @@ class AgentRuntime:
307
307
  if not self.agent.history:
308
308
  return {"kind": "compact_empty"}
309
309
  result = await self.agent.compact()
310
- self.publish_state("history")
310
+ self.publish_state("compacted")
311
311
  return {
312
312
  "kind": "compacted",
313
313
  "original_item_count": result.original_item_count,
@@ -5,10 +5,9 @@ import inspect
5
5
  def run_async(awaitable):
6
6
  """Run an awaitable from synchronous code and return its real result.
7
7
 
8
- This helper is intended for sync call sites (for example, IPython cells)
9
- that need to call async agent APIs without managing the event loop
10
- themselves. It returns the underlying result directly and raises on
11
- failure instead of swallowing exceptions.
8
+ This helper lets synchronous callers use async agent APIs without
9
+ managing the event loop themselves. It returns the underlying result
10
+ directly and propagates exceptions.
12
11
  """
13
12
  try:
14
13
  running_loop = asyncio.get_running_loop()
@@ -3,6 +3,7 @@ import mmap
3
3
  import os
4
4
  import re
5
5
  import typing
6
+ from collections import deque
6
7
  from contextlib import closing
7
8
  from datetime import datetime
8
9
  from pathlib import Path
@@ -323,6 +324,33 @@ def conversation_history_to_turns(
323
324
  return tuple(turns)
324
325
 
325
326
 
327
+ def load_display_history(
328
+ rollout_path: "typing.Union[str, Path]",
329
+ limit: "int" = 80,
330
+ ) -> "typing.Tuple[typing.Union[typing.Tuple[str, str], None], ...]":
331
+ """Read visible turns across checkpoints; None marks a compaction."""
332
+ path = Path(rollout_path).expanduser().resolve()
333
+ turns = deque(maxlen=limit)
334
+ for entry in _iter_rollout_entries(path):
335
+ item_type = entry.get("type")
336
+ payload = entry.get("payload")
337
+ if not isinstance(payload, dict):
338
+ continue
339
+ if item_type == "compacted":
340
+ turns.append(None)
341
+ elif item_type == "event_msg" and payload.get("type") == "user_message":
342
+ turns.append((str(payload.get("message", "")), ""))
343
+ elif (
344
+ item_type == "response_item"
345
+ and payload.get("type") == "message"
346
+ and payload.get("role") == "assistant"
347
+ ):
348
+ if not turns or turns[-1] is None:
349
+ turns.append(("", ""))
350
+ turns[-1] = (turns[-1][0], _extract_response_message_text(payload))
351
+ return tuple(turns)
352
+
353
+
326
354
  def _drop_unmatched_tool_calls(
327
355
  history: "typing.List[ConversationItem]",
328
356
  ) -> "typing.List[ConversationItem]":
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "python-codex"
7
- version = "0.4.0"
7
+ version = "0.4.1"
8
8
  description = "A minimal Python extraction of Codex's main agent loop"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.6.2"
@@ -40,7 +40,7 @@ test = [
40
40
  ]
41
41
  dev = [
42
42
  { include-group = "test" },
43
- "pycodex-ws==0.4.0",
43
+ "pycodex-ws==0.4.1",
44
44
  "black>=22.8.0",
45
45
  "debugpy>=1.8.20; python_version >= '3.8'",
46
46
  "isort>=5.10.1",
File without changes
File without changes