python-codex 0.6.1__tar.gz → 0.6.2__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.
- {python_codex-0.6.1 → python_codex-0.6.2}/PKG-INFO +19 -4
- {python_codex-0.6.1 → python_codex-0.6.2}/README.md +18 -3
- {python_codex-0.6.1 → python_codex-0.6.2}/README_ZH.md +6 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/agent.py +28 -9
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/context.py +40 -28
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/events.py +19 -10
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/protocol.py +15 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/runtime.py +49 -54
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/event_helpers.py +5 -9
- python_codex-0.6.2/pycodex/utils/history.py +92 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/session_persist.py +125 -42
- python_codex-0.6.2/pycodex/utils/skill_catalog.py +18 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pyproject.toml +2 -2
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/gemini_api.py +3 -0
- python_codex-0.6.1/pycodex/utils/history.py +0 -59
- {python_codex-0.6.1 → python_codex-0.6.2}/.gitignore +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/LICENSE +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/__init__.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/__main__.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/bootstrap.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/cli.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/config.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/model.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/multi_agents.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/portable/__init__.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/portable/client.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/portable/protocol.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/portable/server.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/default_base_instructions.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/developer_messages.json +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/goals/budget_limit.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/goals/continuation.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/models.json +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/permissions/approval_policy/never.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/permissions/approval_policy/on_failure.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/permissions/approval_policy/on_request.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/permissions/approval_policy/on_request_rule_request_permission.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/permissions/approval_policy/unless_trusted.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/permissions/sandbox_mode/danger_full_access.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/permissions/sandbox_mode/read_only.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/prompts/permissions/sandbox_mode/workspace_write.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/__init__.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/agent_tool_schemas.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/apply_patch_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/base_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/clock_manager.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/clock_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/code_mode_manager.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/exec_command_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/exec_runtime.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/exec_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/followup_task_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/goal_manager.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/goal_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/grep_files_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/interrupt_agent_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/list_agents_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/list_dir_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/python_tool_schema.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/read_file_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/request_permissions_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/runtime_services.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/send_message_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/shell_command_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/shell_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/spawn_agent_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/unified_exec_manager.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/update_plan_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/view_image_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/wait_agent_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/wait_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/web_search_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/tools/write_stdin_tool.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/__init__.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/_aes_gcm/LICENSE +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/_aes_gcm/README.md +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/_aes_gcm/__init__.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/_aes_gcm/aes.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/_aes_gcm/gcm.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/_aes_gcm/source-sha256.json +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/async_bridge.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/codex_config.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/compactor.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/compat.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/crypto.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/debug.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/doctor.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/dotenv.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/get_env.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/image_utils.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/model_metadata.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/random_ids.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/pycodex/utils/truncation.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/__init__.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/__main__.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/app.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/config.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/messages_api.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/payload_processors.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/request_translation.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/server.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/session_store.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/stream_events.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/stream_router.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/tools/__init__.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/tools/custom_adapter.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/tools/web_search.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/trajectory_dump.py +0 -0
- {python_codex-0.6.1 → python_codex-0.6.2}/responses_server/transport.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-codex
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.2
|
|
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
|
|
@@ -48,6 +48,11 @@ python3 -m pip install --upgrade pycodex-ws
|
|
|
48
48
|
|
|
49
49
|
## Configure a model
|
|
50
50
|
|
|
51
|
+
Start with [config_examples/](config_examples/README.md) for Responses, StepFun,
|
|
52
|
+
Chat Completions, Claude Messages or Gemini. Give an agent your endpoint and key
|
|
53
|
+
(StepFun Coding Plan includes its endpoint) and ask it to follow that guide to
|
|
54
|
+
install and verify a config or profile.
|
|
55
|
+
|
|
51
56
|
Create `~/.codex/config.toml`. For example, with OpenAI:
|
|
52
57
|
|
|
53
58
|
```toml
|
|
@@ -82,6 +87,8 @@ See [configuration](docs/CONTEXT.md#配置读取与-profile) and the
|
|
|
82
87
|
[Gemini setup example](docs/responses_server/README.md#gemini-api).
|
|
83
88
|
Gemini 4 Argon includes a prompt adapted from Antigravity.
|
|
84
89
|
Gemini tool arguments stream as they are generated; tools run after the complete call is received.
|
|
90
|
+
Gemini continuation omits unsigned empty text parts while preserving thought signatures,
|
|
91
|
+
including when resuming recorded sessions.
|
|
85
92
|
|
|
86
93
|
## Use the CLI
|
|
87
94
|
|
|
@@ -95,6 +102,8 @@ pycodex --json "Summarize this repository."
|
|
|
95
102
|
```
|
|
96
103
|
|
|
97
104
|
The first command starts an interactive session; the others run a single task.
|
|
105
|
+
Web skill completion is an [optional frontend feature](packages/pycodex-ws/workspace_server/optional_features/skill-completion/README.md).
|
|
106
|
+
Apply `skill-completion` through Customize to enable @/$ prefix suggestions.
|
|
98
107
|
The agent can edit files and run commands with your user account's permissions.
|
|
99
108
|
|
|
100
109
|
| Command | Purpose |
|
|
@@ -139,9 +148,15 @@ Open `http://127.0.0.1:6007`. The workspace uses the same model configuration as
|
|
|
139
148
|
the CLI and provides conversations, a live HTML Canvas, and file/diff viewers.
|
|
140
149
|
Click file links to inspect code, then select text and use **Insert into chat**
|
|
141
150
|
to include it in your next message.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
151
|
+
Each input displays its author and creation time, including separate messages
|
|
152
|
+
in a steer batch. Recorded messages keep that metadata when the session resumes.
|
|
153
|
+
Restoring a tab reads the rollout tail needed for its latest 80 display rows;
|
|
154
|
+
Agent resume still restores the complete active context after the last checkpoint.
|
|
155
|
+
|
|
156
|
+
The settings menu provides interface customization, password-protected
|
|
157
|
+
workspace sharing, and [One-line Agent](packages/pycodex-ws/README.md#one-line-agent):
|
|
158
|
+
an Agent that runs directly in most shells without installation, for bootstrapping
|
|
159
|
+
an Agent environment or simple debugging. See the [workspace guide](packages/pycodex-ws/README.md) for
|
|
145
160
|
session controls, storage and Feishu setup. A separate
|
|
146
161
|
[VS Code extension](packages/pycodex-ws/extensions/vscode/README.md) connects to
|
|
147
162
|
the same backend, including over Remote SSH.
|
|
@@ -28,6 +28,11 @@ python3 -m pip install --upgrade pycodex-ws
|
|
|
28
28
|
|
|
29
29
|
## Configure a model
|
|
30
30
|
|
|
31
|
+
Start with [config_examples/](config_examples/README.md) for Responses, StepFun,
|
|
32
|
+
Chat Completions, Claude Messages or Gemini. Give an agent your endpoint and key
|
|
33
|
+
(StepFun Coding Plan includes its endpoint) and ask it to follow that guide to
|
|
34
|
+
install and verify a config or profile.
|
|
35
|
+
|
|
31
36
|
Create `~/.codex/config.toml`. For example, with OpenAI:
|
|
32
37
|
|
|
33
38
|
```toml
|
|
@@ -62,6 +67,8 @@ See [configuration](docs/CONTEXT.md#配置读取与-profile) and the
|
|
|
62
67
|
[Gemini setup example](docs/responses_server/README.md#gemini-api).
|
|
63
68
|
Gemini 4 Argon includes a prompt adapted from Antigravity.
|
|
64
69
|
Gemini tool arguments stream as they are generated; tools run after the complete call is received.
|
|
70
|
+
Gemini continuation omits unsigned empty text parts while preserving thought signatures,
|
|
71
|
+
including when resuming recorded sessions.
|
|
65
72
|
|
|
66
73
|
## Use the CLI
|
|
67
74
|
|
|
@@ -75,6 +82,8 @@ pycodex --json "Summarize this repository."
|
|
|
75
82
|
```
|
|
76
83
|
|
|
77
84
|
The first command starts an interactive session; the others run a single task.
|
|
85
|
+
Web skill completion is an [optional frontend feature](packages/pycodex-ws/workspace_server/optional_features/skill-completion/README.md).
|
|
86
|
+
Apply `skill-completion` through Customize to enable @/$ prefix suggestions.
|
|
78
87
|
The agent can edit files and run commands with your user account's permissions.
|
|
79
88
|
|
|
80
89
|
| Command | Purpose |
|
|
@@ -119,9 +128,15 @@ Open `http://127.0.0.1:6007`. The workspace uses the same model configuration as
|
|
|
119
128
|
the CLI and provides conversations, a live HTML Canvas, and file/diff viewers.
|
|
120
129
|
Click file links to inspect code, then select text and use **Insert into chat**
|
|
121
130
|
to include it in your next message.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
Each input displays its author and creation time, including separate messages
|
|
132
|
+
in a steer batch. Recorded messages keep that metadata when the session resumes.
|
|
133
|
+
Restoring a tab reads the rollout tail needed for its latest 80 display rows;
|
|
134
|
+
Agent resume still restores the complete active context after the last checkpoint.
|
|
135
|
+
|
|
136
|
+
The settings menu provides interface customization, password-protected
|
|
137
|
+
workspace sharing, and [One-line Agent](packages/pycodex-ws/README.md#one-line-agent):
|
|
138
|
+
an Agent that runs directly in most shells without installation, for bootstrapping
|
|
139
|
+
an Agent environment or simple debugging. See the [workspace guide](packages/pycodex-ws/README.md) for
|
|
125
140
|
session controls, storage and Feishu setup. A separate
|
|
126
141
|
[VS Code extension](packages/pycodex-ws/extensions/vscode/README.md) connects to
|
|
127
142
|
the same backend, including over Remote SSH.
|
|
@@ -27,6 +27,10 @@ python3 -m pip install --upgrade pycodex-ws
|
|
|
27
27
|
|
|
28
28
|
## 配置模型
|
|
29
29
|
|
|
30
|
+
可从 [config_examples/](config_examples/README.md) 选择 Responses、StepFun、
|
|
31
|
+
Chat Completions、Claude Messages 或 Gemini 模板。向 Agent 提供 endpoint 和 key
|
|
32
|
+
(StepFun Coding Plan 已内置 endpoint),让它按目录说明安装配置或 profile 并验证连接。
|
|
33
|
+
|
|
30
34
|
创建 `~/.codex/config.toml`。以 OpenAI 为例:
|
|
31
35
|
|
|
32
36
|
```toml
|
|
@@ -73,6 +77,8 @@ pycodex --json "概括这个仓库。"
|
|
|
73
77
|
```
|
|
74
78
|
|
|
75
79
|
不带问题时进入交互会话,其他命令执行单次任务。
|
|
80
|
+
网页 skill 补全是 [optional feature](packages/pycodex-ws/workspace_server/optional_features/skill-completion/README.md):
|
|
81
|
+
通过 Customize 应用 `skill-completion` 后启用 @/$ 名称前缀补全。
|
|
76
82
|
Agent 可以修改文件、执行命令,使用当前用户的系统权限。
|
|
77
83
|
|
|
78
84
|
| 命令 | 用途 |
|
|
@@ -13,6 +13,7 @@ from .events import (
|
|
|
13
13
|
CompactFailedEvent,
|
|
14
14
|
CompactStartedEvent,
|
|
15
15
|
Event,
|
|
16
|
+
MessagesAddedEvent,
|
|
16
17
|
ModelCalledEvent,
|
|
17
18
|
ModelCompletedEvent,
|
|
18
19
|
ModelEvent,
|
|
@@ -118,6 +119,7 @@ class Agent:
|
|
|
118
119
|
self._configure_recording(session_id, session_file_path)
|
|
119
120
|
self._last_total_usage_tokens: "typing.Union[int, None]" = None
|
|
120
121
|
self._idle: "typing.Union[asyncio.Event, None]" = None
|
|
122
|
+
self._active_turn_id: "typing.Union[str, None]" = None
|
|
121
123
|
self.is_shutdown = False
|
|
122
124
|
self.accepts_input = True
|
|
123
125
|
self._stop_requested = False
|
|
@@ -209,7 +211,7 @@ class Agent:
|
|
|
209
211
|
def ask(self, text: "str") -> "TurnResult":
|
|
210
212
|
from .utils.async_bridge import run_async
|
|
211
213
|
|
|
212
|
-
return run_async(self.run_turn([text]))
|
|
214
|
+
return run_async(self.run_turn([UserMessage(text)]))
|
|
213
215
|
|
|
214
216
|
def _configure_recording(
|
|
215
217
|
self,
|
|
@@ -260,8 +262,8 @@ class Agent:
|
|
|
260
262
|
self._idle = None
|
|
261
263
|
|
|
262
264
|
async def run_turn(
|
|
263
|
-
self,
|
|
264
|
-
|
|
265
|
+
self, messages: "typing.Iterable[typing.Union[UserMessage, AgentMessage, ToolResult]]",
|
|
266
|
+
turn_id: "typing.Union[str, None]" = None,
|
|
265
267
|
) -> "TurnResult":
|
|
266
268
|
if self.is_shutdown:
|
|
267
269
|
raise RuntimeError("agent is shutdown")
|
|
@@ -271,18 +273,18 @@ class Agent:
|
|
|
271
273
|
self._follow_up_requested = False
|
|
272
274
|
self._idle = asyncio.Event()
|
|
273
275
|
turn = _TurnState(turn_id or uuid7_string())
|
|
276
|
+
self._active_turn_id = turn.turn_id
|
|
274
277
|
try:
|
|
275
|
-
self.
|
|
278
|
+
messages = self._bind_turn(messages)
|
|
279
|
+
self._emit(TurnStartedEvent(turn.turn_id, messages))
|
|
276
280
|
while True:
|
|
277
281
|
phase = "pre_turn" if turn.iteration == 0 else "mid_turn"
|
|
278
282
|
await self._maybe_auto_compact(turn.turn_id, phase)
|
|
283
|
+
if turn.iteration == 0:
|
|
284
|
+
self._append_history(messages)
|
|
279
285
|
self._follow_up_requested = False
|
|
280
286
|
# Input delivery commits history; its failures must fail the turn.
|
|
281
287
|
self.event_handler(TurnInputReadyEvent(turn.turn_id))
|
|
282
|
-
if turn.iteration == 0:
|
|
283
|
-
self.receive_messages(
|
|
284
|
-
tuple(UserMessage(text=text, name=name) for text in texts)
|
|
285
|
-
)
|
|
286
288
|
response = await self._sample(turn)
|
|
287
289
|
self._emit(
|
|
288
290
|
ModelCompletedEvent(
|
|
@@ -347,6 +349,7 @@ class Agent:
|
|
|
347
349
|
finally:
|
|
348
350
|
self._stop_requested = False
|
|
349
351
|
self._follow_up_requested = False
|
|
352
|
+
self._active_turn_id = None
|
|
350
353
|
self._idle.set()
|
|
351
354
|
self._idle = None
|
|
352
355
|
|
|
@@ -479,14 +482,30 @@ class Agent:
|
|
|
479
482
|
)
|
|
480
483
|
return None
|
|
481
484
|
|
|
485
|
+
def _bind_turn(
|
|
486
|
+
self, items: "typing.Iterable[ConversationItem]"
|
|
487
|
+
) -> "typing.Tuple[ConversationItem, ...]":
|
|
488
|
+
turn_id = self._active_turn_id
|
|
489
|
+
return tuple(
|
|
490
|
+
item if isinstance(item, (ToolCall, ToolResult, ReasoningItem))
|
|
491
|
+
else replace(item, turn_id=turn_id) if turn_id is not None
|
|
492
|
+
else item
|
|
493
|
+
for item in items
|
|
494
|
+
)
|
|
495
|
+
|
|
482
496
|
def _append_history(
|
|
483
497
|
self,
|
|
484
498
|
items: "typing.Iterable[ConversationItem]",
|
|
485
499
|
) -> "None":
|
|
486
|
-
items =
|
|
500
|
+
items = self._bind_turn(items)
|
|
487
501
|
if self._rollout_recorder is not None:
|
|
488
502
|
self._rollout_recorder.append_history_items(items, self._history)
|
|
489
503
|
self._history.extend(items)
|
|
504
|
+
messages = tuple(
|
|
505
|
+
item for item in items if isinstance(item, (UserMessage, AgentMessage, AssistantMessage))
|
|
506
|
+
)
|
|
507
|
+
if messages:
|
|
508
|
+
self._emit(MessagesAddedEvent(messages[0].turn_id or "", messages))
|
|
490
509
|
|
|
491
510
|
def _handle_model_stream_event(self, turn_id: "str", event: "ModelEvent") -> "None":
|
|
492
511
|
if isinstance(event, TokenCountEvent):
|
|
@@ -87,6 +87,7 @@ class ContextConfig:
|
|
|
87
87
|
multi_agent_subagent_instructions: "typing.Union[str, None]" = None
|
|
88
88
|
multi_agent_hint: "typing.Union[str, None]" = None
|
|
89
89
|
code_mode_only: "typing.Union[bool, None]" = None
|
|
90
|
+
include_environment_context: "bool" = True
|
|
90
91
|
|
|
91
92
|
def __post_init__(self):
|
|
92
93
|
if self.code_mode_only is not None and not isinstance(self.code_mode_only, bool):
|
|
@@ -228,6 +229,8 @@ class ContextManager:
|
|
|
228
229
|
|
|
229
230
|
def get_turn_metadata(self, turn_id: "str") -> "JSONDict":
|
|
230
231
|
metadata: "JSONDict" = {"turn_id": turn_id}
|
|
232
|
+
if not self.config.include_environment_context:
|
|
233
|
+
return metadata
|
|
231
234
|
if self._workspace_metadata_turn_id is None:
|
|
232
235
|
self._workspace_metadata_turn_id = turn_id
|
|
233
236
|
self._workspace_metadata_cache = get_workspace_turn_metadata(self.cwd)
|
|
@@ -635,44 +638,24 @@ class ContextManager:
|
|
|
635
638
|
return f"{SKILLS_OPEN_TAG}\n{body}\n{SKILLS_CLOSE_TAG}"
|
|
636
639
|
|
|
637
640
|
def _discover_skills(self) -> "typing.List[SkillDescriptor]":
|
|
638
|
-
|
|
639
|
-
if codex_home is None:
|
|
640
|
-
return []
|
|
641
|
-
|
|
642
|
-
user_root = codex_home / "skills"
|
|
643
|
-
system_root = user_root / ".system"
|
|
644
|
-
discovered: "typing.List[SkillDescriptor]" = []
|
|
645
|
-
seen: "typing.Set[Path]" = set()
|
|
646
|
-
|
|
647
|
-
user_paths = _discover_skill_files(user_root, excluded_root=system_root)
|
|
648
|
-
system_paths = _discover_skill_files(system_root)
|
|
649
|
-
|
|
650
|
-
for scope_rank, root, paths in (
|
|
651
|
-
(3, user_root, user_paths),
|
|
652
|
-
(0, system_root, system_paths),
|
|
653
|
-
):
|
|
654
|
-
for path in paths:
|
|
655
|
-
resolved = path.resolve()
|
|
656
|
-
if resolved in seen:
|
|
657
|
-
continue
|
|
658
|
-
seen.add(resolved)
|
|
659
|
-
descriptor = _parse_skill_descriptor(path, scope_rank, root)
|
|
660
|
-
if descriptor is not None:
|
|
661
|
-
discovered.append(descriptor)
|
|
662
|
-
|
|
663
|
-
return discovered
|
|
641
|
+
return discover_skills(self.config.codex_home)
|
|
664
642
|
|
|
665
643
|
def _build_contextual_user_messages(self) -> "typing.List[ContextMessage]":
|
|
666
644
|
sections: "typing.List[str]" = []
|
|
667
645
|
user_instructions = self._merged_user_instructions()
|
|
668
646
|
if user_instructions is not None:
|
|
647
|
+
heading = (
|
|
648
|
+
f"{USER_INSTRUCTIONS_PREFIX}{self.cwd}"
|
|
649
|
+
if self.config.include_environment_context else "# User instructions"
|
|
650
|
+
)
|
|
669
651
|
sections.append(
|
|
670
652
|
(
|
|
671
|
-
f"{
|
|
653
|
+
f"{heading}\n\n"
|
|
672
654
|
f"<INSTRUCTIONS>\n{user_instructions}\n</INSTRUCTIONS>"
|
|
673
655
|
)
|
|
674
656
|
)
|
|
675
|
-
|
|
657
|
+
if self.config.include_environment_context:
|
|
658
|
+
sections.append(self._serialize_environment_context())
|
|
676
659
|
sections.extend(self._extra_contextual_user_messages)
|
|
677
660
|
if not sections:
|
|
678
661
|
return []
|
|
@@ -960,3 +943,32 @@ def build_goal_message(goal, budget_limited=False):
|
|
|
960
943
|
token_budget="none" if budget is None else budget,
|
|
961
944
|
remaining_tokens="unbounded" if budget is None else max(0, budget - goal["tokensUsed"]),
|
|
962
945
|
))
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
def discover_skills(codex_home):
|
|
949
|
+
"""Discover the same skill descriptors used in model context and input menus."""
|
|
950
|
+
if codex_home is None:
|
|
951
|
+
return []
|
|
952
|
+
|
|
953
|
+
user_root = codex_home / "skills"
|
|
954
|
+
system_root = user_root / ".system"
|
|
955
|
+
discovered: "typing.List[SkillDescriptor]" = []
|
|
956
|
+
seen: "typing.Set[Path]" = set()
|
|
957
|
+
|
|
958
|
+
user_paths = _discover_skill_files(user_root, excluded_root=system_root)
|
|
959
|
+
system_paths = _discover_skill_files(system_root)
|
|
960
|
+
|
|
961
|
+
for scope_rank, root, paths in (
|
|
962
|
+
(3, user_root, user_paths),
|
|
963
|
+
(0, system_root, system_paths),
|
|
964
|
+
):
|
|
965
|
+
for path in paths:
|
|
966
|
+
resolved = path.resolve()
|
|
967
|
+
if resolved in seen:
|
|
968
|
+
continue
|
|
969
|
+
seen.add(resolved)
|
|
970
|
+
descriptor = _parse_skill_descriptor(path, scope_rank, root)
|
|
971
|
+
if descriptor is not None:
|
|
972
|
+
discovered.append(descriptor)
|
|
973
|
+
|
|
974
|
+
return discovered
|
|
@@ -5,7 +5,7 @@ import typing
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from typing import ClassVar
|
|
7
7
|
|
|
8
|
-
from .protocol import JSONDict, ToolCall, ToolResult
|
|
8
|
+
from .protocol import AgentMessage, ConversationItem, JSONDict, ToolCall, ToolResult, UserMessage
|
|
9
9
|
from .utils.event_helpers import (
|
|
10
10
|
colorize_cli_message,
|
|
11
11
|
colorize_tool_message,
|
|
@@ -147,12 +147,15 @@ class TerminalEvent(TurnEvent):
|
|
|
147
147
|
@dataclass(frozen=True)
|
|
148
148
|
class TurnStartedEvent(TurnEvent):
|
|
149
149
|
turn_id: "str"
|
|
150
|
-
|
|
150
|
+
messages: "typing.Tuple[ConversationItem, ...]"
|
|
151
151
|
submission_id: "typing.Union[str, None]" = None
|
|
152
152
|
kind: ClassVar[str] = "turn_started"
|
|
153
153
|
|
|
154
154
|
def visualize(self) -> "str":
|
|
155
|
-
return "\n".join(
|
|
155
|
+
return "\n".join(
|
|
156
|
+
message.text for message in self.messages
|
|
157
|
+
if isinstance(message, (UserMessage, AgentMessage)) and message.visible
|
|
158
|
+
)
|
|
156
159
|
|
|
157
160
|
def render(self, display: "EventDisplay") -> "None":
|
|
158
161
|
display.begin_turn(self)
|
|
@@ -167,6 +170,16 @@ class TurnInputReadyEvent(TurnEvent):
|
|
|
167
170
|
kind: ClassVar[str] = "turn_input_ready"
|
|
168
171
|
|
|
169
172
|
|
|
173
|
+
@dataclass(frozen=True)
|
|
174
|
+
class MessagesAddedEvent(TurnEvent):
|
|
175
|
+
"""Conversation items committed to history, in their original order."""
|
|
176
|
+
|
|
177
|
+
turn_id: "str"
|
|
178
|
+
messages: "typing.Tuple[ConversationItem, ...]"
|
|
179
|
+
submission_id: "typing.Union[str, None]" = None
|
|
180
|
+
kind: ClassVar[str] = "messages_added"
|
|
181
|
+
|
|
182
|
+
|
|
170
183
|
@dataclass(frozen=True)
|
|
171
184
|
class TurnCompletedEvent(TerminalEvent):
|
|
172
185
|
turn_id: "str"
|
|
@@ -564,11 +577,7 @@ class SessionStateEvent(Event):
|
|
|
564
577
|
display.inserted_steer_prompts.clear()
|
|
565
578
|
active = state["active_turn"]
|
|
566
579
|
if active is not None:
|
|
567
|
-
|
|
568
|
-
active["turn_id"],
|
|
569
|
-
tuple(active["user_texts"]),
|
|
570
|
-
active["submission_id"],
|
|
571
|
-
).render(display)
|
|
580
|
+
display.set_status("working")
|
|
572
581
|
display.stream_buffer = active["assistant_text"]
|
|
573
582
|
elif not state["busy"]:
|
|
574
583
|
display.set_idle_status(state["background_work_count"])
|
|
@@ -636,7 +645,7 @@ class CommandFailedEvent(Event):
|
|
|
636
645
|
@dataclass(frozen=True)
|
|
637
646
|
class InputQueuedEvent(Event):
|
|
638
647
|
submission_id: "str"
|
|
639
|
-
|
|
648
|
+
message: "UserMessage"
|
|
640
649
|
queue: "str"
|
|
641
650
|
sender: "str"
|
|
642
651
|
explicit_queue: "bool"
|
|
@@ -644,7 +653,7 @@ class InputQueuedEvent(Event):
|
|
|
644
653
|
kind: ClassVar[str] = "input_queued"
|
|
645
654
|
|
|
646
655
|
def render(self, display: "EventDisplay") -> "None":
|
|
647
|
-
preview = shorten_title(self.
|
|
656
|
+
preview = shorten_title(self.message.text, 72)
|
|
648
657
|
if self.explicit_queue:
|
|
649
658
|
display.queued_steer_prompts.setdefault(self.submission_id, []).append(
|
|
650
659
|
preview
|
|
@@ -17,14 +17,20 @@ import json
|
|
|
17
17
|
import typing
|
|
18
18
|
from copy import deepcopy
|
|
19
19
|
from dataclasses import dataclass, field
|
|
20
|
+
from datetime import datetime, timezone
|
|
20
21
|
from typing import Any
|
|
21
22
|
|
|
22
23
|
from .utils.compat import Literal, TypeAlias
|
|
24
|
+
from .utils.random_ids import uuid7_string
|
|
23
25
|
|
|
24
26
|
JSONValue: "TypeAlias" = Any
|
|
25
27
|
JSONDict: "TypeAlias" = typing.Dict[str, Any]
|
|
26
28
|
|
|
27
29
|
|
|
30
|
+
def message_timestamp():
|
|
31
|
+
return datetime.now(timezone.utc).isoformat(timespec="milliseconds")
|
|
32
|
+
|
|
33
|
+
|
|
28
34
|
def qualified_tool_name(name, namespace):
|
|
29
35
|
return name if namespace in (None, "", "functions") else f"{namespace}.{name}"
|
|
30
36
|
|
|
@@ -94,6 +100,9 @@ class UserMessage:
|
|
|
94
100
|
# Local history metadata; serialize() is the model-facing representation.
|
|
95
101
|
name: "str" = "user"
|
|
96
102
|
visible: "bool" = True
|
|
103
|
+
message_id: "str" = field(default_factory=uuid7_string, compare=False)
|
|
104
|
+
created_at: "typing.Union[str, None]" = field(default_factory=message_timestamp, compare=False)
|
|
105
|
+
turn_id: "typing.Union[str, None]" = field(default=None, compare=False)
|
|
97
106
|
|
|
98
107
|
def serialize(self) -> "JSONDict":
|
|
99
108
|
payload = {
|
|
@@ -116,6 +125,9 @@ class AgentMessage:
|
|
|
116
125
|
id: "typing.Union[str, None]" = None
|
|
117
126
|
internal_chat_message_metadata_passthrough: "typing.Union[JSONDict, None]" = None
|
|
118
127
|
visible: "bool" = False
|
|
128
|
+
message_id: "str" = field(default_factory=uuid7_string, compare=False)
|
|
129
|
+
created_at: "typing.Union[str, None]" = field(default_factory=message_timestamp, compare=False)
|
|
130
|
+
turn_id: "typing.Union[str, None]" = field(default=None, compare=False)
|
|
119
131
|
|
|
120
132
|
@property
|
|
121
133
|
def text(self) -> "str":
|
|
@@ -167,6 +179,9 @@ class AssistantMessage:
|
|
|
167
179
|
phase: "typing.Union[str, None]" = None
|
|
168
180
|
content_items: "typing.Union[typing.Tuple[JSONDict, ...], None]" = None
|
|
169
181
|
visible: "bool" = True
|
|
182
|
+
message_id: "str" = field(default_factory=uuid7_string, compare=False)
|
|
183
|
+
created_at: "typing.Union[str, None]" = field(default_factory=message_timestamp, compare=False)
|
|
184
|
+
turn_id: "typing.Union[str, None]" = field(default=None, compare=False)
|
|
170
185
|
|
|
171
186
|
@classmethod
|
|
172
187
|
def from_response_item(cls, payload: "JSONDict") -> "AssistantMessage":
|