python-codex 0.7.0__tar.gz → 0.7.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.7.0 → python_codex-0.7.2}/PKG-INFO +10 -6
- {python_codex-0.7.0 → python_codex-0.7.2}/README.md +9 -5
- {python_codex-0.7.0 → python_codex-0.7.2}/README_ZH.md +7 -4
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/config.py +15 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/events.py +11 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/model.py +85 -1
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/multi_agents.py +2 -2
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/protocol.py +3 -2
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/runtime.py +67 -17
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/__init__.py +3 -1
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/shell_command_tool.py +18 -2
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/unified_exec_manager.py +38 -7
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/event_helpers.py +40 -2
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/get_env.py +57 -5
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/history.py +22 -7
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/session_persist.py +6 -2
- {python_codex-0.7.0 → python_codex-0.7.2}/pyproject.toml +6 -4
- {python_codex-0.7.0 → python_codex-0.7.2}/.gitignore +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/LICENSE +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/__init__.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/__main__.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/agent.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/bootstrap.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/cli.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/context.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/portable/__init__.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/portable/client.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/portable/protocol.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/portable/server.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/default_base_instructions.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/developer_messages.json +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/goals/budget_limit.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/goals/continuation.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/models.json +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/permissions/approval_policy/never.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/permissions/approval_policy/on_failure.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/permissions/approval_policy/on_request.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/permissions/approval_policy/on_request_rule_request_permission.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/permissions/approval_policy/unless_trusted.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/permissions/sandbox_mode/danger_full_access.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/permissions/sandbox_mode/read_only.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/prompts/permissions/sandbox_mode/workspace_write.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/agent_tool_schemas.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/apply_patch_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/base_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/clock_manager.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/clock_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/code_mode_manager.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/exec_command_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/exec_runtime.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/exec_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/followup_task_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/goal_manager.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/goal_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/grep_files_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/interrupt_agent_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/list_agents_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/list_dir_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/python_tool_schema.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/read_file_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/request_permissions_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/runtime_services.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/send_message_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/shell_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/spawn_agent_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/update_plan_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/view_image_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/wait_agent_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/wait_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/web_search_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/tools/write_stdin_tool.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/__init__.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/_aes_gcm/LICENSE +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/_aes_gcm/README.md +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/_aes_gcm/__init__.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/_aes_gcm/aes.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/_aes_gcm/gcm.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/_aes_gcm/source-sha256.json +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/async_bridge.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/codex_config.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/compactor.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/compat.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/crypto.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/debug.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/doctor.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/dotenv.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/http_headers.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/image_utils.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/model_metadata.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/random_ids.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/skill_catalog.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/pycodex/utils/truncation.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/__init__.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/__main__.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/app.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/config.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/gemini_api.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/messages_api.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/payload_processors.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/request_translation.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/server.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/session_store.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/stream_events.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/stream_router.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/tools/__init__.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/tools/custom_adapter.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/tools/web_search.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.2}/responses_server/trajectory_dump.py +0 -0
- {python_codex-0.7.0 → python_codex-0.7.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.7.
|
|
3
|
+
Version: 0.7.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
|
|
@@ -33,7 +33,8 @@ See [upstream alignment](docs/ALIGNMENT.md) for the supported scope and differen
|
|
|
33
33
|
| Package | Includes | Python |
|
|
34
34
|
| --- | --- | --- |
|
|
35
35
|
| `python-codex` | CLI and Python API | 3.6.2+ |
|
|
36
|
-
| `
|
|
36
|
+
| `pyagy` | Core plus Antigravity CLI (`agy`) wire-compatible harness | 3.7+ |
|
|
37
|
+
| `pycodex-ws` | Core, `pyagy`, browser workspace and optional Feishu integration | 3.7+ |
|
|
37
38
|
|
|
38
39
|
For the CLI and Python API:
|
|
39
40
|
|
|
@@ -41,7 +42,7 @@ For the CLI and Python API:
|
|
|
41
42
|
python3 -m pip install --upgrade python-codex
|
|
42
43
|
```
|
|
43
44
|
|
|
44
|
-
For the browser workspace, install `pycodex-ws`; it includes
|
|
45
|
+
For the browser workspace, install `pycodex-ws`; it includes matching `python-codex` and `pyagy` versions:
|
|
45
46
|
|
|
46
47
|
```bash
|
|
47
48
|
python3 -m pip install --upgrade pycodex-ws
|
|
@@ -83,6 +84,11 @@ Use `--profile NAME` to select `NAME.config.toml` beside the base config or an
|
|
|
83
84
|
embedded `[profiles.NAME]` table. Use `--config PATH` for a different config file,
|
|
84
85
|
and `pycodex doctor` to check configuration and connectivity.
|
|
85
86
|
The browser workspace picks up profile changes for new sessions without a restart.
|
|
87
|
+
With `harness = "pyagy"`, Web and Feishu preview the current reasoning text or
|
|
88
|
+
summary until assistant text streams in and takes its place. The browser limits
|
|
89
|
+
the Markdown preview to four lines, lets you scroll longer text, and expands
|
|
90
|
+
the same block for the final reply. Native pycodex exposes reasoning through
|
|
91
|
+
its own event and uses assistant text for the preview.
|
|
86
92
|
|
|
87
93
|
See [configuration](docs/CONTEXT.md#配置读取与-profile) and the
|
|
88
94
|
[Gemini setup example](docs/responses_server/README.md#gemini-api).
|
|
@@ -178,9 +184,7 @@ descriptions and send a feature name, ID or custom request in chat to start the
|
|
|
178
184
|
Settings also provides password-protected sharing
|
|
179
185
|
and [External Call](packages/pycodex-ws/README.md#external-call)
|
|
180
186
|
sessions that connect an external client to a Web conversation. See the [workspace guide](packages/pycodex-ws/README.md) for
|
|
181
|
-
session controls, storage and Feishu setup.
|
|
182
|
-
[VS Code extension](packages/pycodex-ws/extensions/vscode/README.md) connects to
|
|
183
|
-
the same backend, including over Remote SSH.
|
|
187
|
+
session controls, storage and Feishu setup.
|
|
184
188
|
|
|
185
189
|
## Use the Python API
|
|
186
190
|
|
|
@@ -12,7 +12,8 @@ See [upstream alignment](docs/ALIGNMENT.md) for the supported scope and differen
|
|
|
12
12
|
| Package | Includes | Python |
|
|
13
13
|
| --- | --- | --- |
|
|
14
14
|
| `python-codex` | CLI and Python API | 3.6.2+ |
|
|
15
|
-
| `
|
|
15
|
+
| `pyagy` | Core plus Antigravity CLI (`agy`) wire-compatible harness | 3.7+ |
|
|
16
|
+
| `pycodex-ws` | Core, `pyagy`, browser workspace and optional Feishu integration | 3.7+ |
|
|
16
17
|
|
|
17
18
|
For the CLI and Python API:
|
|
18
19
|
|
|
@@ -20,7 +21,7 @@ For the CLI and Python API:
|
|
|
20
21
|
python3 -m pip install --upgrade python-codex
|
|
21
22
|
```
|
|
22
23
|
|
|
23
|
-
For the browser workspace, install `pycodex-ws`; it includes
|
|
24
|
+
For the browser workspace, install `pycodex-ws`; it includes matching `python-codex` and `pyagy` versions:
|
|
24
25
|
|
|
25
26
|
```bash
|
|
26
27
|
python3 -m pip install --upgrade pycodex-ws
|
|
@@ -62,6 +63,11 @@ Use `--profile NAME` to select `NAME.config.toml` beside the base config or an
|
|
|
62
63
|
embedded `[profiles.NAME]` table. Use `--config PATH` for a different config file,
|
|
63
64
|
and `pycodex doctor` to check configuration and connectivity.
|
|
64
65
|
The browser workspace picks up profile changes for new sessions without a restart.
|
|
66
|
+
With `harness = "pyagy"`, Web and Feishu preview the current reasoning text or
|
|
67
|
+
summary until assistant text streams in and takes its place. The browser limits
|
|
68
|
+
the Markdown preview to four lines, lets you scroll longer text, and expands
|
|
69
|
+
the same block for the final reply. Native pycodex exposes reasoning through
|
|
70
|
+
its own event and uses assistant text for the preview.
|
|
65
71
|
|
|
66
72
|
See [configuration](docs/CONTEXT.md#配置读取与-profile) and the
|
|
67
73
|
[Gemini setup example](docs/responses_server/README.md#gemini-api).
|
|
@@ -157,9 +163,7 @@ descriptions and send a feature name, ID or custom request in chat to start the
|
|
|
157
163
|
Settings also provides password-protected sharing
|
|
158
164
|
and [External Call](packages/pycodex-ws/README.md#external-call)
|
|
159
165
|
sessions that connect an external client to a Web conversation. See the [workspace guide](packages/pycodex-ws/README.md) for
|
|
160
|
-
session controls, storage and Feishu setup.
|
|
161
|
-
[VS Code extension](packages/pycodex-ws/extensions/vscode/README.md) connects to
|
|
162
|
-
the same backend, including over Remote SSH.
|
|
166
|
+
session controls, storage and Feishu setup.
|
|
163
167
|
|
|
164
168
|
## Use the Python API
|
|
165
169
|
|
|
@@ -11,7 +11,8 @@ pycodex 用 Python 实现 [Codex](https://github.com/openai/codex) 编程 Agent
|
|
|
11
11
|
| 包 | 内容 | Python |
|
|
12
12
|
| --- | --- | --- |
|
|
13
13
|
| `python-codex` | CLI 和 Python API | 3.6.2+ |
|
|
14
|
-
| `
|
|
14
|
+
| `pyagy` | Core 与 Antigravity CLI(`agy`)协议兼容 harness | 3.7+ |
|
|
15
|
+
| `pycodex-ws` | Core、`pyagy`、浏览器工作区和可选飞书集成 | 3.7+ |
|
|
15
16
|
|
|
16
17
|
使用 CLI 或 Python API:
|
|
17
18
|
|
|
@@ -19,7 +20,7 @@ pycodex 用 Python 实现 [Codex](https://github.com/openai/codex) 编程 Agent
|
|
|
19
20
|
python3 -m pip install --upgrade python-codex
|
|
20
21
|
```
|
|
21
22
|
|
|
22
|
-
使用浏览器工作区则安装 `pycodex-ws`,它会同时安装匹配版本的
|
|
23
|
+
使用浏览器工作区则安装 `pycodex-ws`,它会同时安装匹配版本的 `python-codex` 和 `pyagy`:
|
|
23
24
|
|
|
24
25
|
```bash
|
|
25
26
|
python3 -m pip install --upgrade pycodex-ws
|
|
@@ -59,6 +60,10 @@ export OPENAI_API_KEY="your-api-key"
|
|
|
59
60
|
用 `--profile NAME` 选择同目录的 `NAME.config.toml` 或内嵌的 `[profiles.NAME]`;
|
|
60
61
|
用 `--config PATH` 指定其他配置文件。`pycodex doctor` 可检查配置和连接。
|
|
61
62
|
浏览器工作区会为新会话动态读取 profile,修改配置后无需重启。
|
|
63
|
+
使用 `harness = "pyagy"` 时,Web 和飞书用当前的完整思考文本或摘要作临时预览,
|
|
64
|
+
收到下一段正文后显示累计的回复正文。浏览器在同一个 Markdown 块中显示预览和回复,
|
|
65
|
+
长预览可在约四行高的区域内滚动,定稿后显示全文。
|
|
66
|
+
原生 pycodex 通过独立事件传递推理,预览显示正文。
|
|
62
67
|
|
|
63
68
|
详见[配置文档](docs/CONTEXT.md#配置读取与-profile)和
|
|
64
69
|
[Gemini 配置示例](docs/responses_server/README.md#gemini-api)。
|
|
@@ -138,8 +143,6 @@ pycodex-ws --listen 127.0.0.1:6007 --workspace-config workspaces.json
|
|
|
138
143
|
|
|
139
144
|
设置菜单支持界面定制和带密码的工作区分享。会话操作、存储和飞书配置见
|
|
140
145
|
[工作区指南](packages/pycodex-ws/README.md)。
|
|
141
|
-
独立安装的 [VS Code 扩展](packages/pycodex-ws/extensions/vscode/README.md)
|
|
142
|
-
可连接同一后端,也支持 Remote SSH。
|
|
143
146
|
|
|
144
147
|
## 使用 Python API
|
|
145
148
|
|
|
@@ -10,6 +10,19 @@ from .utils.codex_config import DEFAULT_CODEX_CONFIG_PATH, read_codex_config
|
|
|
10
10
|
from .utils.dotenv import load_codex_dotenv
|
|
11
11
|
from .utils.model_metadata import load_models_by_slug
|
|
12
12
|
|
|
13
|
+
SUPPORTED_HARNESSES = ("pycodex", "pyagy")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _parse_harness(selected: "typing.Mapping[str, typing.Any]") -> "str":
|
|
17
|
+
value = selected.get("harness", "pycodex")
|
|
18
|
+
if not isinstance(value, str) or value not in SUPPORTED_HARNESSES:
|
|
19
|
+
raise ValueError(
|
|
20
|
+
"harness must be one of {0}, got {1!r}".format(
|
|
21
|
+
", ".join(SUPPORTED_HARNESSES), value
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
return value
|
|
25
|
+
|
|
13
26
|
|
|
14
27
|
@dataclass(frozen=True)
|
|
15
28
|
class CodexConfig:
|
|
@@ -17,6 +30,7 @@ class CodexConfig:
|
|
|
17
30
|
profile: "typing.Union[str, None]"
|
|
18
31
|
provider: "ResponsesProviderConfig"
|
|
19
32
|
context: "ContextConfig"
|
|
33
|
+
harness: "str" = "pycodex"
|
|
20
34
|
|
|
21
35
|
@classmethod
|
|
22
36
|
def from_env(
|
|
@@ -35,4 +49,5 @@ class CodexConfig:
|
|
|
35
49
|
profile=selected["profile"],
|
|
36
50
|
provider=ResponsesProviderConfig.from_mapping(selected, model_catalog),
|
|
37
51
|
context=ContextConfig.from_mapping(selected, path, model_catalog),
|
|
52
|
+
harness=_parse_harness(selected),
|
|
38
53
|
)
|
|
@@ -268,6 +268,17 @@ class AssistantDeltaEvent(ModelEvent):
|
|
|
268
268
|
display.set_status("talking")
|
|
269
269
|
|
|
270
270
|
|
|
271
|
+
@dataclass(frozen=True)
|
|
272
|
+
class ReasoningEvent(ModelEvent):
|
|
273
|
+
text: "str"
|
|
274
|
+
turn_id: "str" = ""
|
|
275
|
+
submission_id: "typing.Union[str, None]" = None
|
|
276
|
+
kind: ClassVar[str] = "reasoning"
|
|
277
|
+
|
|
278
|
+
def visualize(self) -> "str":
|
|
279
|
+
return self.text
|
|
280
|
+
|
|
281
|
+
|
|
271
282
|
@dataclass(frozen=True)
|
|
272
283
|
class TokenCountEvent(ModelEvent):
|
|
273
284
|
usage: "typing.Union[JSONDict, None]"
|
|
@@ -25,10 +25,12 @@ from .events import (
|
|
|
25
25
|
ModelEvent,
|
|
26
26
|
ModelRequestInterrupted,
|
|
27
27
|
ModelRequestTimingEvent,
|
|
28
|
+
ReasoningEvent,
|
|
28
29
|
StreamErrorEvent,
|
|
29
30
|
TokenCountEvent,
|
|
30
31
|
ToolCalledEvent,
|
|
31
32
|
)
|
|
33
|
+
from .utils.event_helpers import reasoning_item_text
|
|
32
34
|
from .utils.model_metadata import load_models_by_slug, model_metadata
|
|
33
35
|
from .protocol import (
|
|
34
36
|
AssistantMessage,
|
|
@@ -426,6 +428,12 @@ class ContextLengthExceeded(ResponsesApiError):
|
|
|
426
428
|
self.usage: "typing.Union[typing.Dict[str, int], None]" = None
|
|
427
429
|
self.token_limit: "typing.Union[int, None]" = None
|
|
428
430
|
requested = re.search(r"requested\s+([0-9,]+)\s+tokens", message, re.IGNORECASE)
|
|
431
|
+
if requested is None:
|
|
432
|
+
requested = re.search(
|
|
433
|
+
r"input\s+token\s+count(?:\s*:\s*|\s*\()([0-9,]+)",
|
|
434
|
+
message,
|
|
435
|
+
re.IGNORECASE,
|
|
436
|
+
)
|
|
429
437
|
if requested is not None:
|
|
430
438
|
total = int(requested.group(1).replace(",", ""))
|
|
431
439
|
self.usage = {"total_tokens": total, "input_tokens": total}
|
|
@@ -442,6 +450,12 @@ class ContextLengthExceeded(ResponsesApiError):
|
|
|
442
450
|
message,
|
|
443
451
|
re.IGNORECASE,
|
|
444
452
|
)
|
|
453
|
+
if limit is None:
|
|
454
|
+
limit = re.search(
|
|
455
|
+
r"maximum\s+number\s+of\s+tokens\s+allowed\s*(?:is\s*|\()([0-9,]+)",
|
|
456
|
+
message,
|
|
457
|
+
re.IGNORECASE,
|
|
458
|
+
)
|
|
445
459
|
if limit is not None:
|
|
446
460
|
self.token_limit = int(limit.group(1).replace(",", ""))
|
|
447
461
|
|
|
@@ -1096,6 +1110,39 @@ class ResponsesModelClient:
|
|
|
1096
1110
|
) -> "ModelResponse":
|
|
1097
1111
|
items: "typing.List[typing.Union[typing.Union[AssistantMessage, ToolCall], ReasoningItem]]" = ([])
|
|
1098
1112
|
last_event_type = ""
|
|
1113
|
+
reasoning_item_id: "typing.Union[object, None]" = None
|
|
1114
|
+
raw_reasoning_chunks: "typing.List[str]" = []
|
|
1115
|
+
summary_index: "typing.Union[object, None]" = None
|
|
1116
|
+
summary_chunks: "typing.List[str]" = []
|
|
1117
|
+
last_reasoning = ""
|
|
1118
|
+
last_reasoning_emit_at: "typing.Union[float, None]" = None
|
|
1119
|
+
|
|
1120
|
+
def flush_reasoning(force: "bool" = True) -> "None":
|
|
1121
|
+
nonlocal last_reasoning, last_reasoning_emit_at
|
|
1122
|
+
if not raw_reasoning_chunks and not summary_chunks:
|
|
1123
|
+
return
|
|
1124
|
+
now = monotonic()
|
|
1125
|
+
if (
|
|
1126
|
+
not force
|
|
1127
|
+
and last_reasoning_emit_at is not None
|
|
1128
|
+
and now - last_reasoning_emit_at < 0.08
|
|
1129
|
+
):
|
|
1130
|
+
return
|
|
1131
|
+
raw_text = "".join(raw_reasoning_chunks)
|
|
1132
|
+
text = raw_text if raw_text.strip() else "".join(summary_chunks)
|
|
1133
|
+
if text.strip() and text != last_reasoning:
|
|
1134
|
+
last_reasoning = text
|
|
1135
|
+
last_reasoning_emit_at = now
|
|
1136
|
+
EventScope.emit(ReasoningEvent(text))
|
|
1137
|
+
|
|
1138
|
+
def clear_reasoning_state() -> "None":
|
|
1139
|
+
nonlocal reasoning_item_id, summary_index, last_reasoning, last_reasoning_emit_at
|
|
1140
|
+
reasoning_item_id = None
|
|
1141
|
+
raw_reasoning_chunks.clear()
|
|
1142
|
+
summary_index = None
|
|
1143
|
+
summary_chunks.clear()
|
|
1144
|
+
last_reasoning = ""
|
|
1145
|
+
last_reasoning_emit_at = None
|
|
1099
1146
|
|
|
1100
1147
|
for event_name, data in self._iter_sse_events(response, diagnostics):
|
|
1101
1148
|
if not data:
|
|
@@ -1112,10 +1159,37 @@ class ResponsesModelClient:
|
|
|
1112
1159
|
diagnostics.last_event_type = last_event_type
|
|
1113
1160
|
|
|
1114
1161
|
if event_type == "response.output_text.delta":
|
|
1162
|
+
flush_reasoning()
|
|
1163
|
+
clear_reasoning_state()
|
|
1115
1164
|
EventScope.emit(AssistantDeltaEvent(str(payload.get("delta", ""))))
|
|
1116
1165
|
continue
|
|
1117
1166
|
|
|
1167
|
+
if event_type in (
|
|
1168
|
+
"response.reasoning_text.delta",
|
|
1169
|
+
"response.reasoning_summary_text.delta",
|
|
1170
|
+
):
|
|
1171
|
+
item_id = payload.get("item_id")
|
|
1172
|
+
if item_id != reasoning_item_id:
|
|
1173
|
+
flush_reasoning()
|
|
1174
|
+
clear_reasoning_state()
|
|
1175
|
+
reasoning_item_id = item_id
|
|
1176
|
+
|
|
1177
|
+
if event_type == "response.reasoning_text.delta":
|
|
1178
|
+
raw_reasoning_chunks.append(str(payload.get("delta", "")))
|
|
1179
|
+
else:
|
|
1180
|
+
part_index = payload.get("summary_index", 0)
|
|
1181
|
+
if part_index != summary_index:
|
|
1182
|
+
flush_reasoning()
|
|
1183
|
+
summary_index = part_index
|
|
1184
|
+
summary_chunks.clear()
|
|
1185
|
+
if not raw_reasoning_chunks:
|
|
1186
|
+
last_reasoning_emit_at = None
|
|
1187
|
+
summary_chunks.append(str(payload.get("delta", "")))
|
|
1188
|
+
flush_reasoning(force=False)
|
|
1189
|
+
continue
|
|
1190
|
+
|
|
1118
1191
|
if event_type == "response.output_item.done":
|
|
1192
|
+
flush_reasoning()
|
|
1119
1193
|
item_payload = payload.get("item", {})
|
|
1120
1194
|
if (
|
|
1121
1195
|
isinstance(item_payload, dict)
|
|
@@ -1163,7 +1237,13 @@ class ResponsesModelClient:
|
|
|
1163
1237
|
|
|
1164
1238
|
parsed = self._parse_output_item(item_payload)
|
|
1165
1239
|
if parsed is not None:
|
|
1166
|
-
if isinstance(parsed,
|
|
1240
|
+
if isinstance(parsed, ReasoningItem):
|
|
1241
|
+
streamed_raw = "".join(raw_reasoning_chunks) if item_payload.get("id") == reasoning_item_id else ""
|
|
1242
|
+
text = reasoning_item_text(parsed, streamed_raw)
|
|
1243
|
+
if text and text != last_reasoning:
|
|
1244
|
+
EventScope.emit(ReasoningEvent(text))
|
|
1245
|
+
clear_reasoning_state()
|
|
1246
|
+
elif isinstance(parsed, ToolCall):
|
|
1167
1247
|
EventScope.emit(ToolCalledEvent(parsed.call_id, parsed.name))
|
|
1168
1248
|
items.append(parsed)
|
|
1169
1249
|
if diagnostics is not None:
|
|
@@ -1171,6 +1251,7 @@ class ResponsesModelClient:
|
|
|
1171
1251
|
continue
|
|
1172
1252
|
|
|
1173
1253
|
if event_type == "response.completed":
|
|
1254
|
+
flush_reasoning()
|
|
1174
1255
|
response_payload = payload.get("response")
|
|
1175
1256
|
usage = None
|
|
1176
1257
|
if isinstance(response_payload, dict):
|
|
@@ -1183,6 +1264,7 @@ class ResponsesModelClient:
|
|
|
1183
1264
|
return ModelResponse(items=items, usage=usage)
|
|
1184
1265
|
|
|
1185
1266
|
if event_type == "response.incomplete":
|
|
1267
|
+
flush_reasoning()
|
|
1186
1268
|
partial_items = tuple(items)
|
|
1187
1269
|
reason = self._response_incomplete_reason(payload)
|
|
1188
1270
|
raise ResponsesIncompleteError(
|
|
@@ -1606,6 +1688,8 @@ def _is_context_length_error_message(message: "str") -> "bool":
|
|
|
1606
1688
|
or "maximum context length" in lower
|
|
1607
1689
|
or "exceeds the context window" in lower
|
|
1608
1690
|
or "exceeded the context window" in lower
|
|
1691
|
+
or "exceeds the maximum number of tokens" in lower
|
|
1692
|
+
or "exceeded the maximum number of tokens" in lower
|
|
1609
1693
|
)
|
|
1610
1694
|
|
|
1611
1695
|
|
|
@@ -326,7 +326,7 @@ class AgentsManager:
|
|
|
326
326
|
async def wait_for_activity(self, agent_id, timeout_ms):
|
|
327
327
|
return await self._runtimes[agent_id].wait_for_activity(timeout_ms)
|
|
328
328
|
|
|
329
|
-
def request_close(self, agent_id) -> "None":
|
|
329
|
+
def request_close(self, agent_id, finish_turn=False) -> "None":
|
|
330
330
|
"""Signal a whole subtree before waiting for any of its operations."""
|
|
331
331
|
path = self._runtimes[agent_id].agent.agent_path
|
|
332
332
|
runtimes = [
|
|
@@ -340,7 +340,7 @@ class AgentsManager:
|
|
|
340
340
|
child for child in runtimes
|
|
341
341
|
if child.agent.agent_path.rsplit("/", 1)[0] == runtime.agent.agent_path
|
|
342
342
|
)
|
|
343
|
-
runtime.request_close()
|
|
343
|
+
runtime.request_close(finish_turn)
|
|
344
344
|
|
|
345
345
|
async def shutdown_children(self, agent_id) -> "None":
|
|
346
346
|
# Children may finish and unregister while their parent's turn stops.
|
|
@@ -25,6 +25,7 @@ from .utils.random_ids import uuid7_string
|
|
|
25
25
|
|
|
26
26
|
JSONValue: "TypeAlias" = Any
|
|
27
27
|
JSONDict: "TypeAlias" = typing.Dict[str, Any]
|
|
28
|
+
MessageVisibility: "TypeAlias" = typing.Union[bool, str]
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
def message_timestamp():
|
|
@@ -99,7 +100,7 @@ class UserMessage:
|
|
|
99
100
|
id: "typing.Union[str, None]" = None
|
|
100
101
|
# Local history metadata; serialize() is the model-facing representation.
|
|
101
102
|
name: "str" = "user"
|
|
102
|
-
visible: "
|
|
103
|
+
visible: "MessageVisibility" = True
|
|
103
104
|
message_id: "str" = field(default_factory=uuid7_string, compare=False)
|
|
104
105
|
created_at: "typing.Union[str, None]" = field(default_factory=message_timestamp, compare=False)
|
|
105
106
|
turn_id: "typing.Union[str, None]" = field(default=None, compare=False)
|
|
@@ -124,7 +125,7 @@ class AgentMessage:
|
|
|
124
125
|
content_items: "typing.Tuple[JSONDict, ...]"
|
|
125
126
|
id: "typing.Union[str, None]" = None
|
|
126
127
|
internal_chat_message_metadata_passthrough: "typing.Union[JSONDict, None]" = None
|
|
127
|
-
visible: "
|
|
128
|
+
visible: "MessageVisibility" = False
|
|
128
129
|
message_id: "str" = field(default_factory=uuid7_string, compare=False)
|
|
129
130
|
created_at: "typing.Union[str, None]" = field(default_factory=message_timestamp, compare=False)
|
|
130
131
|
turn_id: "typing.Union[str, None]" = field(default=None, compare=False)
|
|
@@ -8,19 +8,27 @@ from time import monotonic
|
|
|
8
8
|
|
|
9
9
|
from .agent import Agent
|
|
10
10
|
from .events import (
|
|
11
|
+
AssistantDeltaEvent,
|
|
12
|
+
AutoCompactCompletedEvent,
|
|
11
13
|
BASE_EVENT_HANDLER,
|
|
12
14
|
CommandCompletedEvent,
|
|
13
15
|
CommandFailedEvent,
|
|
14
16
|
CommandStartedEvent,
|
|
17
|
+
CompactCompletedEvent,
|
|
15
18
|
Event,
|
|
16
19
|
EventScope,
|
|
17
20
|
InputQueuedEvent,
|
|
18
21
|
InputRequestedEvent,
|
|
19
22
|
InputResolvedEvent,
|
|
23
|
+
MessagesAddedEvent,
|
|
24
|
+
ModelCalledEvent,
|
|
20
25
|
ModelRequestInterrupted,
|
|
26
|
+
ReasoningEvent,
|
|
21
27
|
RuntimeUpdatedEvent,
|
|
22
28
|
SessionClosedEvent,
|
|
23
29
|
SessionStateEvent,
|
|
30
|
+
StreamErrorEvent,
|
|
31
|
+
ToolStartedEvent,
|
|
24
32
|
TurnEvent,
|
|
25
33
|
TurnInterrupted,
|
|
26
34
|
)
|
|
@@ -28,7 +36,7 @@ from .model import ModelControl, RetryCodes, matches_retry_codes
|
|
|
28
36
|
from .protocol import AgentMessage, ToolResult, TurnResult, UserMessage
|
|
29
37
|
from .tools.runtime_services import close_resources
|
|
30
38
|
from .utils import uuid7_string
|
|
31
|
-
from .utils.event_helpers import shorten_title, visible_input_text
|
|
39
|
+
from .utils.event_helpers import last_reasoning_text, shorten_title, visible_input_text
|
|
32
40
|
from .utils.history import conversation_history_to_turns
|
|
33
41
|
from .utils.truncation import truncate_tool_result_for_history
|
|
34
42
|
from .utils.session_persist import (
|
|
@@ -41,6 +49,12 @@ if typing.TYPE_CHECKING:
|
|
|
41
49
|
from .multi_agents import AgentsManager
|
|
42
50
|
|
|
43
51
|
|
|
52
|
+
_INVOKE_VISIBLE_TAGS = {
|
|
53
|
+
"clock_tick": "Wake-up",
|
|
54
|
+
"exec_command_completed": "Task done",
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
44
58
|
class SubmissionInterrupted(RuntimeError):
|
|
45
59
|
def __init__(self) -> "None":
|
|
46
60
|
super().__init__("submission interrupted")
|
|
@@ -256,12 +270,27 @@ class AgentRuntime:
|
|
|
256
270
|
"history": conversation_history_to_turns(self.agent.history),
|
|
257
271
|
}
|
|
258
272
|
|
|
273
|
+
def active_turn_snapshot(self):
|
|
274
|
+
active = self._active_turn
|
|
275
|
+
if active is None:
|
|
276
|
+
return None
|
|
277
|
+
return {
|
|
278
|
+
"turn_id": active.turn_id,
|
|
279
|
+
"submission_id": self._current_submission.submission_id
|
|
280
|
+
if self._current_submission is not None else active.turn_id,
|
|
281
|
+
"messages": active.messages,
|
|
282
|
+
"assistant_text": active.assistant_text,
|
|
283
|
+
"reasoning": self._stream_reasoning,
|
|
284
|
+
"model_errors": list(active.model_errors),
|
|
285
|
+
}
|
|
286
|
+
|
|
259
287
|
def state_snapshot(self):
|
|
260
288
|
"""Current frontend state, without completed conversation history."""
|
|
261
289
|
agent = self.agent
|
|
262
290
|
execution = agent.execution_snapshot()
|
|
263
291
|
client = typing.cast(ModelControl, agent.model_client)
|
|
264
|
-
|
|
292
|
+
status = self._last_agent_status
|
|
293
|
+
failed = status == "interrupted" or isinstance(status, dict) and "errored" in status
|
|
265
294
|
pending = []
|
|
266
295
|
if self._triggered_submission is not None:
|
|
267
296
|
pending.append(("steer", self._triggered_submission))
|
|
@@ -276,14 +305,8 @@ class AgentRuntime:
|
|
|
276
305
|
"reasoning_effort": client.reasoning_effort,
|
|
277
306
|
},
|
|
278
307
|
"running": execution.running,
|
|
279
|
-
"
|
|
280
|
-
|
|
281
|
-
"submission_id": self._current_submission.submission_id
|
|
282
|
-
if self._current_submission is not None else active.turn_id,
|
|
283
|
-
"messages": active.messages,
|
|
284
|
-
"assistant_text": active.assistant_text,
|
|
285
|
-
"model_errors": list(active.model_errors),
|
|
286
|
-
},
|
|
308
|
+
"last_reasoning": last_reasoning_text(agent.history) if self._active_turn is None and not failed else "",
|
|
309
|
+
"active_turn": self.active_turn_snapshot(),
|
|
287
310
|
"queued_inputs": [
|
|
288
311
|
{
|
|
289
312
|
"submission_id": item.submission_id,
|
|
@@ -371,20 +394,29 @@ class AgentRuntime:
|
|
|
371
394
|
if self._queue_event is not None:
|
|
372
395
|
self._queue_event.set()
|
|
373
396
|
|
|
374
|
-
async def close(self):
|
|
375
|
-
"""Stop admission across the subtree and wait for issued work and cleanup.
|
|
397
|
+
async def close(self, finish_turn=False):
|
|
398
|
+
"""Stop admission across the subtree and wait for issued work and cleanup.
|
|
399
|
+
|
|
400
|
+
With ``finish_turn`` active turns run to their natural end instead of
|
|
401
|
+
receiving a cooperative stop; only waits are woken early.
|
|
402
|
+
"""
|
|
376
403
|
if self._worker is None:
|
|
377
404
|
self._worker = asyncio.create_task(self._run_forever())
|
|
378
405
|
if self.accepts_input:
|
|
379
|
-
self.agents_manager.request_close(self.agent.agent_id)
|
|
406
|
+
self.agents_manager.request_close(self.agent.agent_id, finish_turn)
|
|
380
407
|
await asyncio.shield(self._worker)
|
|
381
408
|
|
|
382
|
-
def request_close(self):
|
|
409
|
+
def request_close(self, finish_turn=False):
|
|
383
410
|
"""Manager-only local signal, after it captures this node's children."""
|
|
384
411
|
if not self.accepts_input:
|
|
385
412
|
return
|
|
386
413
|
self.agent.accepts_input = False
|
|
387
|
-
|
|
414
|
+
if not finish_turn:
|
|
415
|
+
self.stop_asap()
|
|
416
|
+
elif self.agent.is_running:
|
|
417
|
+
self._wait_interrupted = True
|
|
418
|
+
if self._input_activity is not None:
|
|
419
|
+
self._input_activity.set()
|
|
388
420
|
pending = list(self._enqueue_queue)
|
|
389
421
|
if self._triggered_submission is not None:
|
|
390
422
|
pending.append(self._triggered_submission)
|
|
@@ -712,7 +744,7 @@ class AgentRuntime:
|
|
|
712
744
|
f"</{tag}>"
|
|
713
745
|
)
|
|
714
746
|
await self.start()
|
|
715
|
-
self.message(text)
|
|
747
|
+
self.message(UserMessage(text, visible=_INVOKE_VISIBLE_TAGS.get(tag, tag)))
|
|
716
748
|
_submission_id, future = self.trigger()
|
|
717
749
|
await future
|
|
718
750
|
return True
|
|
@@ -812,6 +844,9 @@ class AgentRuntime:
|
|
|
812
844
|
await waiter
|
|
813
845
|
except asyncio.CancelledError:
|
|
814
846
|
pass
|
|
847
|
+
if not self.accepts_input:
|
|
848
|
+
# A graceful close cannot wait for input that will never arrive.
|
|
849
|
+
self.stop_asap()
|
|
815
850
|
if self._wait_interrupted:
|
|
816
851
|
return {"message": "Wait interrupted by new input.", "timed_out": False}
|
|
817
852
|
if self._steer_queue:
|
|
@@ -913,6 +948,7 @@ class AgentRuntime:
|
|
|
913
948
|
return
|
|
914
949
|
|
|
915
950
|
self._last_agent_status = "running"
|
|
951
|
+
self._stream_reasoning = ""
|
|
916
952
|
self._turn_started_at = monotonic()
|
|
917
953
|
self._turn_finished_at = None
|
|
918
954
|
final_answer = None
|
|
@@ -921,7 +957,12 @@ class AgentRuntime:
|
|
|
921
957
|
self._active_turn = turn
|
|
922
958
|
turn.deliver_messages = self._deliver_messages
|
|
923
959
|
if not self.title:
|
|
924
|
-
prompt =
|
|
960
|
+
prompt = "\n".join(
|
|
961
|
+
message.text
|
|
962
|
+
for message in turn.messages
|
|
963
|
+
if isinstance(message, (UserMessage, AgentMessage))
|
|
964
|
+
and message.visible is True
|
|
965
|
+
).strip()
|
|
925
966
|
if prompt:
|
|
926
967
|
self.title = shorten_title(prompt)
|
|
927
968
|
self.publish_state("auto_title")
|
|
@@ -946,6 +987,15 @@ class AgentRuntime:
|
|
|
946
987
|
|
|
947
988
|
@EventScope.router
|
|
948
989
|
def _publish_agent_event(self, event: "Event") -> "None":
|
|
990
|
+
if isinstance(event, ReasoningEvent):
|
|
991
|
+
self._stream_reasoning = event.text
|
|
992
|
+
elif isinstance(event, AssistantDeltaEvent) and event.delta:
|
|
993
|
+
self._stream_reasoning = ""
|
|
994
|
+
elif isinstance(event, (
|
|
995
|
+
MessagesAddedEvent, StreamErrorEvent, ModelCalledEvent, ToolStartedEvent,
|
|
996
|
+
AutoCompactCompletedEvent, CompactCompletedEvent,
|
|
997
|
+
)):
|
|
998
|
+
self._stream_reasoning = last_reasoning_text(self.agent.history)
|
|
949
999
|
queued = self._current_submission
|
|
950
1000
|
if isinstance(event, TurnEvent) and queued is not None and event.turn_id == queued.turn_id:
|
|
951
1001
|
event = replace(event, submission_id=event.submission_id or queued.submission_id)
|
|
@@ -108,7 +108,9 @@ def get_tools(
|
|
|
108
108
|
restart=code_mode_manager.restart, close=code_mode_manager.close,
|
|
109
109
|
)
|
|
110
110
|
elif tool is exec_command_tool:
|
|
111
|
-
runtime_environment.register_resource(
|
|
111
|
+
runtime_environment.register_resource(
|
|
112
|
+
tool.name, unified_exec_manager, close=unified_exec_manager.close,
|
|
113
|
+
)
|
|
112
114
|
elif tool is set_period_tool:
|
|
113
115
|
runtime_environment.register_resource("clock", clock_manager)
|
|
114
116
|
return registry
|
|
@@ -12,8 +12,11 @@ Expected behavior:
|
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
14
|
import asyncio
|
|
15
|
+
import os
|
|
16
|
+
import subprocess
|
|
15
17
|
|
|
16
18
|
from ..protocol import JSONDict, JSONValue
|
|
19
|
+
from ..utils.get_env import build_shell_command
|
|
17
20
|
from .base_tool import BaseTool, ToolContext
|
|
18
21
|
|
|
19
22
|
DEFAULT_SHELL_TIMEOUT_MS = 10_000
|
|
@@ -61,7 +64,10 @@ class ShellCommandTool(BaseTool):
|
|
|
61
64
|
login = bool(args.get("login", True))
|
|
62
65
|
workdir_arg = args.get("workdir")
|
|
63
66
|
working_directory = context.resolve_path(workdir_arg)
|
|
64
|
-
|
|
67
|
+
if os.name == "nt":
|
|
68
|
+
shell_args = build_shell_command(command, login=login)
|
|
69
|
+
else:
|
|
70
|
+
shell_args = ["bash", "-lc" if login else "-c", command]
|
|
65
71
|
|
|
66
72
|
process = await asyncio.create_subprocess_exec(
|
|
67
73
|
*shell_args,
|
|
@@ -77,7 +83,17 @@ class ShellCommandTool(BaseTool):
|
|
|
77
83
|
)
|
|
78
84
|
timed_out = False
|
|
79
85
|
except asyncio.TimeoutError:
|
|
80
|
-
|
|
86
|
+
if os.name == "nt":
|
|
87
|
+
try:
|
|
88
|
+
subprocess.run(
|
|
89
|
+
["taskkill", "/F", "/T", "/PID", str(process.pid)],
|
|
90
|
+
stdout=subprocess.DEVNULL,
|
|
91
|
+
stderr=subprocess.DEVNULL,
|
|
92
|
+
)
|
|
93
|
+
except OSError:
|
|
94
|
+
process.kill()
|
|
95
|
+
else:
|
|
96
|
+
process.kill()
|
|
81
97
|
stdout_bytes, stderr_bytes = await process.communicate()
|
|
82
98
|
timed_out = True
|
|
83
99
|
|