python-codex 0.5.2__tar.gz → 0.6.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 (124) hide show
  1. python_codex-0.6.1/PKG-INFO +201 -0
  2. python_codex-0.6.1/README.md +181 -0
  3. python_codex-0.6.1/README_ZH.md +175 -0
  4. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/__init__.py +22 -12
  5. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/agent.py +89 -74
  6. python_codex-0.6.1/pycodex/bootstrap.py +160 -0
  7. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/cli.py +19 -28
  8. python_codex-0.6.1/pycodex/config.py +36 -0
  9. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/context.py +368 -51
  10. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/events.py +14 -187
  11. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/model.py +197 -95
  12. python_codex-0.6.1/pycodex/multi_agents.py +401 -0
  13. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/portable/__init__.py +8 -6
  14. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/portable/client.py +24 -39
  15. python_codex-0.6.1/pycodex/portable/protocol.py +28 -0
  16. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/portable/server.py +3 -3
  17. python_codex-0.6.1/pycodex/prompts/developer_messages.json +13 -0
  18. python_codex-0.6.1/pycodex/prompts/goals/budget_limit.md +19 -0
  19. python_codex-0.6.1/pycodex/prompts/goals/continuation.md +56 -0
  20. python_codex-0.6.1/pycodex/prompts/models.json +1833 -0
  21. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/protocol.py +81 -15
  22. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/runtime.py +370 -226
  23. python_codex-0.6.1/pycodex/tools/__init__.py +153 -0
  24. python_codex-0.6.1/pycodex/tools/agent_tool_schemas.py +30 -0
  25. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/apply_patch_tool.py +17 -34
  26. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/base_tool.py +63 -35
  27. python_codex-0.5.2/pycodex/tools/clock_tool.py → python_codex-0.6.1/pycodex/tools/clock_manager.py +44 -105
  28. python_codex-0.6.1/pycodex/tools/clock_tool.py +114 -0
  29. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/code_mode_manager.py +165 -246
  30. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/exec_command_tool.py +0 -18
  31. python_codex-0.6.1/pycodex/tools/exec_runtime.py +332 -0
  32. python_codex-0.6.1/pycodex/tools/exec_tool.py +105 -0
  33. python_codex-0.6.1/pycodex/tools/followup_task_tool.py +44 -0
  34. python_codex-0.6.1/pycodex/tools/goal_manager.py +205 -0
  35. python_codex-0.6.1/pycodex/tools/goal_tool.py +126 -0
  36. python_codex-0.6.1/pycodex/tools/interrupt_agent_tool.py +48 -0
  37. python_codex-0.6.1/pycodex/tools/list_agents_tool.py +66 -0
  38. python_codex-0.6.1/pycodex/tools/python_tool_schema.py +141 -0
  39. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/request_permissions_tool.py +1 -0
  40. python_codex-0.6.1/pycodex/tools/runtime_services.py +222 -0
  41. python_codex-0.6.1/pycodex/tools/send_message_tool.py +42 -0
  42. python_codex-0.6.1/pycodex/tools/spawn_agent_tool.py +83 -0
  43. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/unified_exec_manager.py +26 -35
  44. python_codex-0.6.1/pycodex/tools/wait_agent_tool.py +65 -0
  45. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/wait_tool.py +24 -13
  46. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/web_search_tool.py +1 -0
  47. python_codex-0.6.1/pycodex/utils/codex_config.py +105 -0
  48. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/compactor.py +4 -0
  49. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/compat.py +43 -2
  50. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/doctor.py +5 -4
  51. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/dotenv.py +0 -7
  52. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/event_helpers.py +143 -13
  53. python_codex-0.6.1/pycodex/utils/history.py +59 -0
  54. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/session_persist.py +104 -48
  55. {python_codex-0.5.2 → python_codex-0.6.1}/pyproject.toml +2 -2
  56. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/__init__.py +2 -0
  57. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/app.py +10 -7
  58. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/config.py +6 -12
  59. python_codex-0.6.1/responses_server/gemini_api.py +333 -0
  60. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/messages_api.py +9 -1
  61. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/payload_processors.py +4 -4
  62. python_codex-0.6.1/responses_server/request_translation.py +486 -0
  63. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/server.py +31 -24
  64. python_codex-0.6.1/responses_server/stream_events.py +124 -0
  65. python_codex-0.6.1/responses_server/stream_router.py +371 -0
  66. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/tools/custom_adapter.py +29 -29
  67. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/tools/web_search.py +3 -0
  68. python_codex-0.6.1/responses_server/transport.py +388 -0
  69. python_codex-0.5.2/PKG-INFO +0 -262
  70. python_codex-0.5.2/README.md +0 -242
  71. python_codex-0.5.2/README_ZH.md +0 -179
  72. python_codex-0.5.2/pycodex/bootstrap.py +0 -374
  73. python_codex-0.5.2/pycodex/prompts/models.json +0 -890
  74. python_codex-0.5.2/pycodex/tools/__init__.py +0 -61
  75. python_codex-0.5.2/pycodex/tools/agent_tool_schemas.py +0 -68
  76. python_codex-0.5.2/pycodex/tools/close_agent_tool.py +0 -60
  77. python_codex-0.5.2/pycodex/tools/exec_runtime.js +0 -161
  78. python_codex-0.5.2/pycodex/tools/exec_tool.py +0 -62
  79. python_codex-0.5.2/pycodex/tools/request_user_input_tool.py +0 -102
  80. python_codex-0.5.2/pycodex/tools/resume_agent_tool.py +0 -54
  81. python_codex-0.5.2/pycodex/tools/runtime_services.py +0 -550
  82. python_codex-0.5.2/pycodex/tools/send_input_tool.py +0 -110
  83. python_codex-0.5.2/pycodex/tools/spawn_agent_tool.py +0 -122
  84. python_codex-0.5.2/pycodex/tools/wait_agent_tool.py +0 -85
  85. python_codex-0.5.2/responses_server/stream_router.py +0 -1153
  86. {python_codex-0.5.2 → python_codex-0.6.1}/.gitignore +0 -0
  87. {python_codex-0.5.2 → python_codex-0.6.1}/LICENSE +0 -0
  88. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/__main__.py +0 -0
  89. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/prompts/default_base_instructions.md +0 -0
  90. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/prompts/permissions/approval_policy/never.md +0 -0
  91. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/prompts/permissions/approval_policy/on_failure.md +0 -0
  92. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/prompts/permissions/approval_policy/on_request.md +0 -0
  93. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/prompts/permissions/approval_policy/on_request_rule_request_permission.md +0 -0
  94. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/prompts/permissions/approval_policy/unless_trusted.md +0 -0
  95. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/prompts/permissions/sandbox_mode/danger_full_access.md +0 -0
  96. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/prompts/permissions/sandbox_mode/read_only.md +0 -0
  97. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/prompts/permissions/sandbox_mode/workspace_write.md +0 -0
  98. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/grep_files_tool.py +0 -0
  99. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/list_dir_tool.py +0 -0
  100. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/read_file_tool.py +0 -0
  101. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/shell_command_tool.py +0 -0
  102. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/shell_tool.py +0 -0
  103. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/update_plan_tool.py +0 -0
  104. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/view_image_tool.py +0 -0
  105. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/tools/write_stdin_tool.py +0 -0
  106. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/__init__.py +0 -0
  107. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/_aes_gcm/LICENSE +0 -0
  108. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/_aes_gcm/README.md +0 -0
  109. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/_aes_gcm/__init__.py +0 -0
  110. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/_aes_gcm/aes.py +0 -0
  111. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/_aes_gcm/gcm.py +0 -0
  112. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/_aes_gcm/source-sha256.json +0 -0
  113. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/async_bridge.py +0 -0
  114. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/crypto.py +0 -0
  115. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/debug.py +0 -0
  116. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/get_env.py +0 -0
  117. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/image_utils.py +0 -0
  118. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/model_metadata.py +0 -0
  119. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/random_ids.py +0 -0
  120. {python_codex-0.5.2 → python_codex-0.6.1}/pycodex/utils/truncation.py +0 -0
  121. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/__main__.py +0 -0
  122. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/session_store.py +0 -0
  123. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/tools/__init__.py +0 -0
  124. {python_codex-0.5.2 → python_codex-0.6.1}/responses_server/trajectory_dump.py +0 -0
@@ -0,0 +1,201 @@
1
+ Metadata-Version: 2.1
2
+ Name: python-codex
3
+ Version: 0.6.1
4
+ Summary: A minimal Python extraction of Codex's main agent loop
5
+ License-File: LICENSE
6
+ Requires-Python: >=3.6.2
7
+ Requires-Dist: dataclasses>=0.8; python_version < '3.7'
8
+ Requires-Dist: importlib-metadata>=4.8.3; python_version < '3.8'
9
+ Requires-Dist: loguru>=0.7.3
10
+ Requires-Dist: prompt-toolkit>=3.0.36
11
+ Requires-Dist: pyyaml>=6.0
12
+ Requires-Dist: requests>=2.27.1
13
+ Requires-Dist: starlette<0.20,>=0.19.1; python_version < '3.7'
14
+ Requires-Dist: starlette>=0.19.1; python_version >= '3.7'
15
+ Requires-Dist: tomli<2,>=1.2.3; python_version < '3.11'
16
+ Requires-Dist: typing-extensions>=4.1.1; python_version < '3.8'
17
+ Requires-Dist: uvicorn<0.17,>=0.16.0; python_version < '3.7'
18
+ Requires-Dist: uvicorn>=0.16.0; python_version >= '3.7'
19
+ Description-Content-Type: text/markdown
20
+
21
+ # pycodex
22
+
23
+ [中文](README_ZH.md)
24
+
25
+ pycodex is a Python implementation of the [Codex](https://github.com/openai/codex)
26
+ coding agent. Use it in a terminal, in a browser, or from your own Python code.
27
+ It supports file editing, command execution, multiple agents and saved sessions.
28
+ See [upstream alignment](docs/ALIGNMENT.md) for the supported scope and differences.
29
+
30
+ ## Install
31
+
32
+ | Package | Includes | Python |
33
+ | --- | --- | --- |
34
+ | `python-codex` | CLI and Python API | 3.6.2+ |
35
+ | `pycodex-ws` | Core plus browser workspace and optional Feishu integration | 3.7+ |
36
+
37
+ For the CLI and Python API:
38
+
39
+ ```bash
40
+ python3 -m pip install --upgrade python-codex
41
+ ```
42
+
43
+ For the browser workspace, install `pycodex-ws`; it includes the matching core version:
44
+
45
+ ```bash
46
+ python3 -m pip install --upgrade pycodex-ws
47
+ ```
48
+
49
+ ## Configure a model
50
+
51
+ Create `~/.codex/config.toml`. For example, with OpenAI:
52
+
53
+ ```toml
54
+ model = "gpt-5.4"
55
+ model_provider = "openai"
56
+ ```
57
+
58
+ Supply the API key through the environment or `~/.codex/.env`:
59
+
60
+ ```bash
61
+ export OPENAI_API_KEY="your-api-key"
62
+ ```
63
+
64
+ For another provider, configure its `base_url` and `env_key`. Select the API with
65
+ `compat_api` in the profile or provider table:
66
+
67
+ | `compat_api` | API |
68
+ | --- | --- |
69
+ | `"none"` (default) | Responses |
70
+ | `"chat_completions"` | Chat Completions, including Step |
71
+ | `"messages"` | Claude Messages |
72
+ | `"gemini"` | Gemini API |
73
+
74
+ Legacy `use_chat_completion = true/false` remains supported as `chat_completions/none`.
75
+
76
+ Use `--profile NAME` to select `NAME.config.toml` beside the base config or an
77
+ embedded `[profiles.NAME]` table. Use `--config PATH` for a different config file,
78
+ and `pycodex doctor` to check configuration and connectivity.
79
+ The browser workspace picks up profile changes for new sessions without a restart.
80
+
81
+ See [configuration](docs/CONTEXT.md#配置读取与-profile) and the
82
+ [Gemini setup example](docs/responses_server/README.md#gemini-api).
83
+ Gemini 4 Argon includes a prompt adapted from Antigravity.
84
+ Gemini tool arguments stream as they are generated; tools run after the complete call is received.
85
+
86
+ ## Use the CLI
87
+
88
+ Run these commands from your project directory:
89
+
90
+ ```bash
91
+ pycodex
92
+ pycodex "Summarize this repository."
93
+ pycodex --profile my_profile "Review the latest changes."
94
+ pycodex --json "Summarize this repository."
95
+ ```
96
+
97
+ The first command starts an interactive session; the others run a single task.
98
+ The agent can edit files and run commands with your user account's permissions.
99
+
100
+ | Command | Purpose |
101
+ | --- | --- |
102
+ | `/model`, `/effort` | View or change the model and reasoning effort |
103
+ | `/cd <directory>` | Change directory while idle |
104
+ | `/title`, `/history` | Manage the title and inspect conversation history |
105
+ | `/resume` | List or resume saved sessions |
106
+ | `/compact` | Summarize history to free context |
107
+ | `/queue <message>` | Submit a task after the current one finishes |
108
+
109
+ Send a message while the agent is working to redirect it, or use `/queue` to
110
+ wait. Sessions are saved under `~/.codex/sessions` by default.
111
+ Ctrl+C or Ctrl+D closes the session after issued operations finish.
112
+ Run `pycodex --help` for all options.
113
+
114
+ For a local vLLM server:
115
+
116
+ ```bash
117
+ pycodex --vllm-endpoint http://127.0.0.1:18000
118
+ ```
119
+
120
+ ## Use the browser workspace
121
+
122
+ After installing `pycodex-ws`, create `workspaces.json`:
123
+
124
+ ```json
125
+ {
126
+ "workspaces": [
127
+ {"id": "demo", "work_dir": ".", "state_path": "demo", "enable_board": true}
128
+ ]
129
+ }
130
+ ```
131
+
132
+ Start the server and keep the terminal open:
133
+
134
+ ```bash
135
+ pycodex-ws --listen 127.0.0.1:6007 --workspace-config workspaces.json
136
+ ```
137
+
138
+ Open `http://127.0.0.1:6007`. The workspace uses the same model configuration as
139
+ the CLI and provides conversations, a live HTML Canvas, and file/diff viewers.
140
+ Click file links to inspect code, then select text and use **Insert into chat**
141
+ to include it in your next message.
142
+
143
+ The settings menu provides interface customization and password-protected
144
+ workspace sharing. See the [workspace guide](packages/pycodex-ws/README.md) for
145
+ session controls, storage and Feishu setup. A separate
146
+ [VS Code extension](packages/pycodex-ws/extensions/vscode/README.md) connects to
147
+ the same backend, including over Remote SSH.
148
+
149
+ ## Use the Python API
150
+
151
+ Save this as `example.py` and run `python3 example.py`. It uses the model
152
+ configuration above and the standard tools:
153
+
154
+ ```python
155
+ from contextlib import closing
156
+
157
+ from pycodex import AgentsManager, CodexConfig
158
+ from pycodex.bootstrap import build_model
159
+ from pycodex.utils.async_bridge import run_async
160
+
161
+
162
+ async def main():
163
+ config = CodexConfig.from_env()
164
+ with closing(build_model(config.provider)) as model:
165
+ runtime = AgentsManager(
166
+ model.client, config.context,
167
+ ).create_root_runtime()
168
+ try:
169
+ await runtime.start()
170
+ receipt = await runtime.submit_input("Summarize this repository.")
171
+ print((await receipt.future).output_text)
172
+ finally:
173
+ await runtime.close()
174
+
175
+
176
+ run_async(main())
177
+ ```
178
+
179
+ `AgentsManager` creates the runtime; `submit_input` submits work.
180
+ Await `receipt.future` for the result. The example closes the runtime and any
181
+ local compatibility server when finished. See [runtime contracts](docs/RUNTIME.md#ownership) for
182
+ custom models, tools and integrations.
183
+
184
+ ## More features
185
+
186
+ - [Portable configuration](docs/PORTABLE.md): transfer encrypted configuration, instructions and skills to another machine.
187
+ - [Frontend customization](packages/pycodex-ws/README.md#customize-the-interface): change the workspace through an Agent conversation or your own CSS/JavaScript.
188
+ - [Responses compatibility server](docs/responses_server/README.md): expose a supported backend through the Responses API.
189
+ - [Retries and fallback models](docs/RUNTIME.md#responses-reliability): configure recovery from model failures.
190
+
191
+ ## Development
192
+
193
+ From the repository root:
194
+
195
+ ```bash
196
+ env -u VIRTUAL_ENV uv sync --dev
197
+ env -u VIRTUAL_ENV uv run --dev pytest
198
+ ```
199
+
200
+ See the [development guide](AGENTS.md), [test guide](tests/TESTS.md),
201
+ [runtime architecture](docs/RUNTIME.md) and [workspace API](docs/WORKSPACE_API.md).
@@ -0,0 +1,181 @@
1
+ # pycodex
2
+
3
+ [中文](README_ZH.md)
4
+
5
+ pycodex is a Python implementation of the [Codex](https://github.com/openai/codex)
6
+ coding agent. Use it in a terminal, in a browser, or from your own Python code.
7
+ It supports file editing, command execution, multiple agents and saved sessions.
8
+ See [upstream alignment](docs/ALIGNMENT.md) for the supported scope and differences.
9
+
10
+ ## Install
11
+
12
+ | Package | Includes | Python |
13
+ | --- | --- | --- |
14
+ | `python-codex` | CLI and Python API | 3.6.2+ |
15
+ | `pycodex-ws` | Core plus browser workspace and optional Feishu integration | 3.7+ |
16
+
17
+ For the CLI and Python API:
18
+
19
+ ```bash
20
+ python3 -m pip install --upgrade python-codex
21
+ ```
22
+
23
+ For the browser workspace, install `pycodex-ws`; it includes the matching core version:
24
+
25
+ ```bash
26
+ python3 -m pip install --upgrade pycodex-ws
27
+ ```
28
+
29
+ ## Configure a model
30
+
31
+ Create `~/.codex/config.toml`. For example, with OpenAI:
32
+
33
+ ```toml
34
+ model = "gpt-5.4"
35
+ model_provider = "openai"
36
+ ```
37
+
38
+ Supply the API key through the environment or `~/.codex/.env`:
39
+
40
+ ```bash
41
+ export OPENAI_API_KEY="your-api-key"
42
+ ```
43
+
44
+ For another provider, configure its `base_url` and `env_key`. Select the API with
45
+ `compat_api` in the profile or provider table:
46
+
47
+ | `compat_api` | API |
48
+ | --- | --- |
49
+ | `"none"` (default) | Responses |
50
+ | `"chat_completions"` | Chat Completions, including Step |
51
+ | `"messages"` | Claude Messages |
52
+ | `"gemini"` | Gemini API |
53
+
54
+ Legacy `use_chat_completion = true/false` remains supported as `chat_completions/none`.
55
+
56
+ Use `--profile NAME` to select `NAME.config.toml` beside the base config or an
57
+ embedded `[profiles.NAME]` table. Use `--config PATH` for a different config file,
58
+ and `pycodex doctor` to check configuration and connectivity.
59
+ The browser workspace picks up profile changes for new sessions without a restart.
60
+
61
+ See [configuration](docs/CONTEXT.md#配置读取与-profile) and the
62
+ [Gemini setup example](docs/responses_server/README.md#gemini-api).
63
+ Gemini 4 Argon includes a prompt adapted from Antigravity.
64
+ Gemini tool arguments stream as they are generated; tools run after the complete call is received.
65
+
66
+ ## Use the CLI
67
+
68
+ Run these commands from your project directory:
69
+
70
+ ```bash
71
+ pycodex
72
+ pycodex "Summarize this repository."
73
+ pycodex --profile my_profile "Review the latest changes."
74
+ pycodex --json "Summarize this repository."
75
+ ```
76
+
77
+ The first command starts an interactive session; the others run a single task.
78
+ The agent can edit files and run commands with your user account's permissions.
79
+
80
+ | Command | Purpose |
81
+ | --- | --- |
82
+ | `/model`, `/effort` | View or change the model and reasoning effort |
83
+ | `/cd <directory>` | Change directory while idle |
84
+ | `/title`, `/history` | Manage the title and inspect conversation history |
85
+ | `/resume` | List or resume saved sessions |
86
+ | `/compact` | Summarize history to free context |
87
+ | `/queue <message>` | Submit a task after the current one finishes |
88
+
89
+ Send a message while the agent is working to redirect it, or use `/queue` to
90
+ wait. Sessions are saved under `~/.codex/sessions` by default.
91
+ Ctrl+C or Ctrl+D closes the session after issued operations finish.
92
+ Run `pycodex --help` for all options.
93
+
94
+ For a local vLLM server:
95
+
96
+ ```bash
97
+ pycodex --vllm-endpoint http://127.0.0.1:18000
98
+ ```
99
+
100
+ ## Use the browser workspace
101
+
102
+ After installing `pycodex-ws`, create `workspaces.json`:
103
+
104
+ ```json
105
+ {
106
+ "workspaces": [
107
+ {"id": "demo", "work_dir": ".", "state_path": "demo", "enable_board": true}
108
+ ]
109
+ }
110
+ ```
111
+
112
+ Start the server and keep the terminal open:
113
+
114
+ ```bash
115
+ pycodex-ws --listen 127.0.0.1:6007 --workspace-config workspaces.json
116
+ ```
117
+
118
+ Open `http://127.0.0.1:6007`. The workspace uses the same model configuration as
119
+ the CLI and provides conversations, a live HTML Canvas, and file/diff viewers.
120
+ Click file links to inspect code, then select text and use **Insert into chat**
121
+ to include it in your next message.
122
+
123
+ The settings menu provides interface customization and password-protected
124
+ workspace sharing. See the [workspace guide](packages/pycodex-ws/README.md) for
125
+ session controls, storage and Feishu setup. A separate
126
+ [VS Code extension](packages/pycodex-ws/extensions/vscode/README.md) connects to
127
+ the same backend, including over Remote SSH.
128
+
129
+ ## Use the Python API
130
+
131
+ Save this as `example.py` and run `python3 example.py`. It uses the model
132
+ configuration above and the standard tools:
133
+
134
+ ```python
135
+ from contextlib import closing
136
+
137
+ from pycodex import AgentsManager, CodexConfig
138
+ from pycodex.bootstrap import build_model
139
+ from pycodex.utils.async_bridge import run_async
140
+
141
+
142
+ async def main():
143
+ config = CodexConfig.from_env()
144
+ with closing(build_model(config.provider)) as model:
145
+ runtime = AgentsManager(
146
+ model.client, config.context,
147
+ ).create_root_runtime()
148
+ try:
149
+ await runtime.start()
150
+ receipt = await runtime.submit_input("Summarize this repository.")
151
+ print((await receipt.future).output_text)
152
+ finally:
153
+ await runtime.close()
154
+
155
+
156
+ run_async(main())
157
+ ```
158
+
159
+ `AgentsManager` creates the runtime; `submit_input` submits work.
160
+ Await `receipt.future` for the result. The example closes the runtime and any
161
+ local compatibility server when finished. See [runtime contracts](docs/RUNTIME.md#ownership) for
162
+ custom models, tools and integrations.
163
+
164
+ ## More features
165
+
166
+ - [Portable configuration](docs/PORTABLE.md): transfer encrypted configuration, instructions and skills to another machine.
167
+ - [Frontend customization](packages/pycodex-ws/README.md#customize-the-interface): change the workspace through an Agent conversation or your own CSS/JavaScript.
168
+ - [Responses compatibility server](docs/responses_server/README.md): expose a supported backend through the Responses API.
169
+ - [Retries and fallback models](docs/RUNTIME.md#responses-reliability): configure recovery from model failures.
170
+
171
+ ## Development
172
+
173
+ From the repository root:
174
+
175
+ ```bash
176
+ env -u VIRTUAL_ENV uv sync --dev
177
+ env -u VIRTUAL_ENV uv run --dev pytest
178
+ ```
179
+
180
+ See the [development guide](AGENTS.md), [test guide](tests/TESTS.md),
181
+ [runtime architecture](docs/RUNTIME.md) and [workspace API](docs/WORKSPACE_API.md).
@@ -0,0 +1,175 @@
1
+ # pycodex
2
+
3
+ [English](README.md)
4
+
5
+ pycodex 用 Python 实现 [Codex](https://github.com/openai/codex) 编程 Agent,
6
+ 可在终端、浏览器或自己的 Python 程序中使用,支持文件编辑、命令执行、
7
+ 多 Agent 协作和会话恢复。支持范围及与上游的差异见[对齐文档](docs/ALIGNMENT.md)。
8
+
9
+ ## 安装
10
+
11
+ | 包 | 内容 | Python |
12
+ | --- | --- | --- |
13
+ | `python-codex` | CLI 和 Python API | 3.6.2+ |
14
+ | `pycodex-ws` | Core、浏览器工作区和可选飞书集成 | 3.7+ |
15
+
16
+ 使用 CLI 或 Python API:
17
+
18
+ ```bash
19
+ python3 -m pip install --upgrade python-codex
20
+ ```
21
+
22
+ 使用浏览器工作区则安装 `pycodex-ws`,它会同时安装匹配版本的 core:
23
+
24
+ ```bash
25
+ python3 -m pip install --upgrade pycodex-ws
26
+ ```
27
+
28
+ ## 配置模型
29
+
30
+ 创建 `~/.codex/config.toml`。以 OpenAI 为例:
31
+
32
+ ```toml
33
+ model = "gpt-5.4"
34
+ model_provider = "openai"
35
+ ```
36
+
37
+ API key 通过环境变量或 `~/.codex/.env` 提供:
38
+
39
+ ```bash
40
+ export OPENAI_API_KEY="your-api-key"
41
+ ```
42
+
43
+ 其他 provider 需要配置 `base_url` 和 `env_key`,并在 profile 或 provider 中
44
+ 用 `compat_api` 选择接口:
45
+
46
+ | `compat_api` | 接口 |
47
+ | --- | --- |
48
+ | `"none"`(默认) | Responses |
49
+ | `"chat_completions"` | Chat Completions,包括 Step |
50
+ | `"messages"` | Claude Messages |
51
+ | `"gemini"` | Gemini API |
52
+
53
+ 旧配置 `use_chat_completion = true/false` 仍可用,分别对应 `chat_completions/none`。
54
+
55
+ 用 `--profile NAME` 选择同目录的 `NAME.config.toml` 或内嵌的 `[profiles.NAME]`;
56
+ 用 `--config PATH` 指定其他配置文件。`pycodex doctor` 可检查配置和连接。
57
+ 浏览器工作区会为新会话动态读取 profile,修改配置后无需重启。
58
+
59
+ 详见[配置文档](docs/CONTEXT.md#配置读取与-profile)和
60
+ [Gemini 配置示例](docs/responses_server/README.md#gemini-api)。
61
+ Gemini 4 Argon 内置基于 Antigravity 适配的提示词。
62
+ Gemini 工具参数支持流式接收,完整调用收到后再执行工具。
63
+
64
+ ## 使用 CLI
65
+
66
+ 在项目目录中运行:
67
+
68
+ ```bash
69
+ pycodex
70
+ pycodex "概括这个仓库。"
71
+ pycodex --profile my_profile "审查最近的改动。"
72
+ pycodex --json "概括这个仓库。"
73
+ ```
74
+
75
+ 不带问题时进入交互会话,其他命令执行单次任务。
76
+ Agent 可以修改文件、执行命令,使用当前用户的系统权限。
77
+
78
+ | 命令 | 用途 |
79
+ | --- | --- |
80
+ | `/model`、`/effort` | 查看或切换模型及推理强度 |
81
+ | `/cd <directory>` | 空闲时切换目录 |
82
+ | `/title`、`/history` | 管理标题、查看历史 |
83
+ | `/resume` | 列出或恢复已保存会话 |
84
+ | `/compact` | 压缩历史,释放上下文 |
85
+ | `/queue <message>` | 等当前任务完成后再执行 |
86
+
87
+ Agent 工作时可直接发送消息调整方向,或用 `/queue` 排队。
88
+ 会话默认保存在 `~/.codex/sessions`。
89
+ Ctrl+C 或 Ctrl+D 会在已发出的操作完成后退出。完整选项见 `pycodex --help`。
90
+
91
+ 接入本地 vLLM 服务:
92
+
93
+ ```bash
94
+ pycodex --vllm-endpoint http://127.0.0.1:18000
95
+ ```
96
+
97
+ ## 使用浏览器工作区
98
+
99
+ 安装 `pycodex-ws` 后,创建 `workspaces.json`:
100
+
101
+ ```json
102
+ {
103
+ "workspaces": [
104
+ {"id": "demo", "work_dir": ".", "state_path": "demo", "enable_board": true}
105
+ ]
106
+ }
107
+ ```
108
+
109
+ 启动服务并保持终端打开:
110
+
111
+ ```bash
112
+ pycodex-ws --listen 127.0.0.1:6007 --workspace-config workspaces.json
113
+ ```
114
+
115
+ 访问 `http://127.0.0.1:6007`。工作区沿用 CLI 的模型配置,提供对话、
116
+ 实时 HTML Canvas 和文件/diff 查看器。点击文件链接查看代码,选中文字后
117
+ 用 **Insert into chat** 加入下一条消息。
118
+
119
+ 设置菜单支持界面定制和带密码的工作区分享。会话操作、存储和飞书配置见
120
+ [工作区指南](packages/pycodex-ws/README.md)。
121
+ 独立安装的 [VS Code 扩展](packages/pycodex-ws/extensions/vscode/README.md)
122
+ 可连接同一后端,也支持 Remote SSH。
123
+
124
+ ## 使用 Python API
125
+
126
+ 将以下代码保存为 `example.py`,运行 `python3 example.py`。
127
+ 它会使用前面的模型配置和内置工具:
128
+
129
+ ```python
130
+ from contextlib import closing
131
+
132
+ from pycodex import AgentsManager, CodexConfig
133
+ from pycodex.bootstrap import build_model
134
+ from pycodex.utils.async_bridge import run_async
135
+
136
+
137
+ async def main():
138
+ config = CodexConfig.from_env()
139
+ with closing(build_model(config.provider)) as model:
140
+ runtime = AgentsManager(
141
+ model.client, config.context,
142
+ ).create_root_runtime()
143
+ try:
144
+ await runtime.start()
145
+ receipt = await runtime.submit_input("概括这个仓库。")
146
+ print((await receipt.future).output_text)
147
+ finally:
148
+ await runtime.close()
149
+
150
+
151
+ run_async(main())
152
+ ```
153
+
154
+ `AgentsManager` 创建 runtime,`submit_input` 提交任务,等待 `receipt.future` 获取结果。
155
+ 示例结束时会关闭 runtime 和本地兼容服务。
156
+ 自定义模型、工具与集成方式见[运行时文档](docs/RUNTIME.md#ownership)。
157
+
158
+ ## 更多功能
159
+
160
+ - [Portable 配置](docs/PORTABLE.md):将配置、指令和 skills 加密迁移到其他机器。
161
+ - [界面定制](packages/pycodex-ws/README.md#customize-the-interface):通过 Agent 对话或 CSS/JavaScript 修改工作区。
162
+ - [Responses 兼容服务](docs/responses_server/README.md):通过 Responses API 接入支持的模型后端。
163
+ - [重试与备用模型](docs/RUNTIME.md#responses-reliability):配置模型故障后的恢复策略。
164
+
165
+ ## 开发
166
+
167
+ 在仓库根目录运行:
168
+
169
+ ```bash
170
+ env -u VIRTUAL_ENV uv sync --dev
171
+ env -u VIRTUAL_ENV uv run --dev pytest
172
+ ```
173
+
174
+ 参考[开发约定](AGENTS.md)、[测试指南](tests/TESTS.md)、
175
+ [运行时架构](docs/RUNTIME.md)和[工作区 API](docs/WORKSPACE_API.md)。
@@ -9,12 +9,17 @@ from .model import (
9
9
  NOOP_MODEL_STREAM_EVENT_HANDLER,
10
10
  ContextLengthExceeded,
11
11
  ModelClient,
12
+ ModelControl,
13
+ ModelRecordingMetadata,
12
14
  ResponsesApiError,
13
15
  ResponsesIncompleteError,
14
16
  ResponsesModelClient,
15
17
  ResponsesProviderConfig,
16
18
  )
19
+ from .config import CodexConfig
20
+ from .multi_agents import AgentsManager
17
21
  from .protocol import (
22
+ AgentMessage,
18
23
  AssistantMessage,
19
24
  ContextMessage,
20
25
  ModelResponse,
@@ -31,28 +36,28 @@ from .tools.runtime_services import (
31
36
  PlanStore,
32
37
  RequestPermissionsManager,
33
38
  RequestUserInputManager,
34
- SubAgentManager,
35
39
  create_agent_runtime_environment,
36
40
  )
37
41
  from .tools import (
38
42
  ApplyPatchTool,
39
43
  BaseTool,
40
44
  ClockManager,
41
- ClockTool,
42
- CloseAgentTool,
43
45
  CodeModeManager,
44
46
  ExecCommandTool,
45
47
  ExecTool,
48
+ FollowupTaskTool,
46
49
  GrepFilesTool,
50
+ InterruptAgentTool,
51
+ ListAgentsTool,
47
52
  ListDirTool,
48
53
  ReadFileTool,
49
54
  Registry,
50
55
  RequestPermissionsTool,
51
- RequestUserInputTool,
52
- ResumeAgentTool,
53
- SendInputTool,
56
+ SendMessageTool,
57
+ SetPeriodTool,
54
58
  ShellCommandTool,
55
59
  ShellTool,
60
+ SleepTool,
56
61
  SpawnAgentTool,
57
62
  ToolContext,
58
63
  ToolRegistry,
@@ -71,29 +76,34 @@ __all__ = [
71
76
  "ContextLengthExceeded",
72
77
  "Event",
73
78
  "Agent",
79
+ "AgentMessage",
74
80
  "AgentRuntime",
81
+ "AgentsManager",
75
82
  "TurnInterrupted",
76
83
  "ApplyPatchTool",
77
84
  "AssistantMessage",
78
85
  "BaseTool",
79
86
  "ClockManager",
80
- "ClockTool",
81
- "CloseAgentTool",
82
87
  "create_agent_runtime_environment",
83
88
  "CodeModeManager",
89
+ "CodexConfig",
84
90
  "ContextConfig",
85
91
  "ContextManager",
86
92
  "ContextMessage",
87
93
  "ExecTool",
88
94
  "ExecCommandTool",
95
+ "FollowupTaskTool",
89
96
  "GrepFilesTool",
97
+ "InterruptAgentTool",
98
+ "ListAgentsTool",
90
99
  "ListDirTool",
91
100
  "ModelClient",
101
+ "ModelControl",
102
+ "ModelRecordingMetadata",
92
103
  "NOOP_MODEL_STREAM_EVENT_HANDLER",
93
104
  "Registry",
94
105
  "ReadFileTool",
95
106
  "RequestPermissionsTool",
96
- "RequestUserInputTool",
97
107
  "ModelResponse",
98
108
  "ModelEvent",
99
109
  "PlanStore",
@@ -101,16 +111,16 @@ __all__ = [
101
111
  "ReasoningItem",
102
112
  "RequestPermissionsManager",
103
113
  "RequestUserInputManager",
104
- "ResumeAgentTool",
105
114
  "ResponsesApiError",
106
115
  "ResponsesIncompleteError",
107
116
  "ResponsesModelClient",
108
117
  "ResponsesProviderConfig",
109
- "SendInputTool",
118
+ "SendMessageTool",
119
+ "SetPeriodTool",
110
120
  "ShellCommandTool",
111
121
  "ShellTool",
122
+ "SleepTool",
112
123
  "SpawnAgentTool",
113
- "SubAgentManager",
114
124
  "ToolCall",
115
125
  "ToolContext",
116
126
  "ToolRegistry",