python-codex 0.7.1__py3-none-any.whl → 0.7.2__py3-none-any.whl

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.
@@ -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
- shell_args = ["bash", "-lc" if login else "-c", command]
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
- process.kill()
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
 
@@ -26,6 +26,7 @@ from loguru import logger
26
26
 
27
27
  from ..protocol import JSONValue
28
28
  from ..utils.compat import shlex_join, stream_writer_is_closing
29
+ from ..utils.get_env import build_shell_command
29
30
  from ..utils.truncation import (
30
31
  DEFAULT_MAX_OUTPUT_TOKENS,
31
32
  approx_token_count,
@@ -433,13 +434,12 @@ class UnifiedExecManager:
433
434
  shell: "typing.Union[str, None]",
434
435
  login: "bool",
435
436
  ) -> "typing.List[str]":
436
- shell_path = shell or os.environ.get("SHELL") or "/bin/bash"
437
- shell_name = Path(shell_path).name.lower()
438
- if shell_name in {"cmd", "cmd.exe"}:
439
- return [shell_path, "/C", cmd]
440
- if "powershell" in shell_name:
441
- return [shell_path, "-NoProfile", "-Command", cmd]
442
- return [shell_path, "-lc" if login else "-c", cmd]
437
+ return build_shell_command(
438
+ cmd,
439
+ shell=shell,
440
+ login=login,
441
+ default_posix="/bin/bash",
442
+ )
443
443
 
444
444
  def _truncate_output(
445
445
  self, output: "str", max_output_tokens: "typing.Union[int, None]"
pycodex/utils/get_env.py CHANGED
@@ -1,16 +1,68 @@
1
1
  import os
2
2
  import platform
3
+ import shutil
3
4
  import subprocess
4
5
  import typing
5
6
  from datetime import datetime
6
- from pathlib import Path
7
+ from pathlib import Path, PureWindowsPath
7
8
 
8
9
 
9
- def get_shell_name() -> "str":
10
- shell_path = os.environ.get("SHELL")
10
+ def resolve_default_shell_path(default_posix: "str" = "/bin/bash") -> "str":
11
+ shell_path = (os.environ.get("SHELL") or "").strip()
11
12
  if shell_path:
12
- return Path(shell_path).name or shell_path
13
- return "bash"
13
+ if os.name != "nt":
14
+ return shell_path
15
+ if not shell_path.startswith("/") or os.path.isfile(shell_path):
16
+ return shell_path
17
+ win_equiv = shutil.which(PureWindowsPath(shell_path).name)
18
+ if win_equiv:
19
+ return win_equiv
20
+ if os.name == "nt":
21
+ for candidate in ("powershell.exe", "powershell", "pwsh.exe", "pwsh"):
22
+ resolved = shutil.which(candidate)
23
+ if resolved:
24
+ return resolved
25
+ return os.environ.get("COMSPEC") or "cmd.exe"
26
+ return default_posix
27
+
28
+
29
+ def build_shell_command(
30
+ cmd: "str",
31
+ shell: "typing.Union[str, None]" = None,
32
+ login: "bool" = True,
33
+ default_posix: "str" = "/bin/bash",
34
+ ) -> "typing.List[str]":
35
+ shell_path = shell or resolve_default_shell_path(default_posix=default_posix)
36
+ shell_name = (
37
+ PureWindowsPath(shell_path).name.lower()
38
+ if os.name == "nt"
39
+ else Path(shell_path).name.lower()
40
+ )
41
+ if shell_name in {"cmd", "cmd.exe"}:
42
+ return [shell_path, "/C", cmd]
43
+ if "powershell" in shell_name or shell_name in {"pwsh", "pwsh.exe"}:
44
+ return [shell_path, "-NoProfile", "-Command", cmd]
45
+ return [shell_path, "-lc" if login else "-c", cmd]
46
+
47
+
48
+ def get_shell_name() -> "str":
49
+ if os.name != "nt":
50
+ shell_path = os.environ.get("SHELL")
51
+ if shell_path:
52
+ return Path(shell_path).name or shell_path
53
+ return "bash"
54
+ resolved = resolve_default_shell_path()
55
+ name = PureWindowsPath(resolved).name or resolved
56
+ lower = name.lower()
57
+ if "powershell" in lower:
58
+ return "powershell"
59
+ if lower in {"pwsh", "pwsh.exe"}:
60
+ return "pwsh"
61
+ if lower in {"cmd", "cmd.exe"}:
62
+ return "cmd"
63
+ if lower.endswith(".exe"):
64
+ return name[:-4]
65
+ return name
14
66
 
15
67
 
16
68
  def get_timezone_name() -> "str":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-codex
3
- Version: 0.7.1
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
@@ -49,10 +49,10 @@ pycodex/tools/read_file_tool.py,sha256=YK__uhIVldBjAQega5S_ZuZU5jgP_kLOwr-YhjAmR
49
49
  pycodex/tools/request_permissions_tool.py,sha256=t-Y-iEhvUyE9IJAeiwnzfUdbQ73Gw7uxFcWLwS0no4o,4000
50
50
  pycodex/tools/runtime_services.py,sha256=59Vg22uQ6F0VPokAVf8x5AXdSdmj8_FffBzheD6RLFo,7810
51
51
  pycodex/tools/send_message_tool.py,sha256=mH51ufxTCcsHuLFI1tDKyX14AHPMij2cMJLJdlFFjZQ,1414
52
- pycodex/tools/shell_command_tool.py,sha256=bJKlTdIs2i28vH5f4GZfpunezr6JNicRzsL_6Vc3HvU,3675
52
+ pycodex/tools/shell_command_tool.py,sha256=iRQOHg1eTUPkntGc-ClyqyvNxI6JFGkT4S1heCj-8KA,4242
53
53
  pycodex/tools/shell_tool.py,sha256=I6lYLABSmLddRrNmpk0Li83AV55MI8x0bckWaRkFGI0,3527
54
54
  pycodex/tools/spawn_agent_tool.py,sha256=yjkjHsUxGdSHOn9_kZTs8Bd-0ZnWznZxOfcy3E-WKcA,3596
55
- pycodex/tools/unified_exec_manager.py,sha256=CC3lxhiEl5yBqEypkS_dfmliaT7ERwv0u58zQCDoMD4,15926
55
+ pycodex/tools/unified_exec_manager.py,sha256=vYghA6o7PGsDfYY9sYDpDYdDaRxuM5VBSsQa85STloY,15757
56
56
  pycodex/tools/update_plan_tool.py,sha256=xwrSrerw5qfkbFc9Ltx1OZEmD__CWtryOy3UhL0-Jp4,3198
57
57
  pycodex/tools/view_image_tool.py,sha256=H7OP-QZEU5Gf-E4YnQbXfu2hDkL5-dJ3Apla2YYjErQ,3754
58
58
  pycodex/tools/wait_agent_tool.py,sha256=uo4KcFZBm8BAmw7i_wVjg2i3f_T9PrGL4ZnxbGt3-38,2516
@@ -69,7 +69,7 @@ pycodex/utils/debug.py,sha256=5XMpWpwFSm6woyx6RGXvN2qL0afRtTQbwlOAv-LotTw,913
69
69
  pycodex/utils/doctor.py,sha256=xhPflFEYFfmtQ4-LjnIyz-cNts0GjNtAK0inVTYfKiI,10764
70
70
  pycodex/utils/dotenv.py,sha256=rLHBfz5zPZMbrJqyRyYPy3j4oiDwuzfrH4mDH3XRrow,1647
71
71
  pycodex/utils/event_helpers.py,sha256=fzVvCJ3u8zi0FseuTJi7OcpVnNuASwEwIMwUcuurInw,13732
72
- pycodex/utils/get_env.py,sha256=L4S8h84tkgxZKvrxY7ezTgePbXepG-yIigUTKeY6uuE,6094
72
+ pycodex/utils/get_env.py,sha256=fHIl1-Z0UP-KM9uQrmIm8GDgWsk3Kuxq2OEBSB0PLEI,7927
73
73
  pycodex/utils/history.py,sha256=EsXbZFvtMrzZ99dkthjPmdN5ZvOjUI6WCFVNImi5G5M,4495
74
74
  pycodex/utils/http_headers.py,sha256=4Jlnmun6QFSQ6L7javlDQfom1p2AZZQFXvcHzD3_cQk,877
75
75
  pycodex/utils/image_utils.py,sha256=OUzUs0Cow4L8Z2np0EBeEUotAqqsCmRmhrV8AxZUXRw,2460
@@ -101,8 +101,8 @@ responses_server/transport.py,sha256=-pR-8zMxarSOH8H62i6IaG9nxi-IcWibRQarXs3Nk-s
101
101
  responses_server/tools/__init__.py,sha256=ivsBSEy0SBUhY-Uea5v1XMLXShkwHdCVl0id-1FwdZg,150
102
102
  responses_server/tools/custom_adapter.py,sha256=leYNJKp4Ute0JWNfGpe-ntSyFqRgYCdWF4dMYQFINlk,8615
103
103
  responses_server/tools/web_search.py,sha256=JyF6NHCS0SqoBrO18jX8cgBsiV4OYQBPz0Ky4u3juSQ,9059
104
- python_codex-0.7.1.dist-info/METADATA,sha256=sqpv6usBJFmgaQapfJ6M_qoyYwMFmvD97KFnKsiI2wE,10077
105
- python_codex-0.7.1.dist-info/WHEEL,sha256=KGYbc1zXlYddvwxnNty23BeaKzh7YuoSIvIMO4jEhvw,87
106
- python_codex-0.7.1.dist-info/entry_points.txt,sha256=sNUVakoVuTrzJH505ZgRTQxmtRRPUHV_EH0i6EbYTyM,45
107
- python_codex-0.7.1.dist-info/licenses/LICENSE,sha256=0X8ifk312hYAORM4hlzg8wVSEXYKNmiPgWlB1YIy2Nw,10926
108
- python_codex-0.7.1.dist-info/RECORD,,
104
+ python_codex-0.7.2.dist-info/METADATA,sha256=6KwWNAfiOTFloeF5536qyYH690p2yBX41LU9pbZ17YM,10077
105
+ python_codex-0.7.2.dist-info/WHEEL,sha256=KGYbc1zXlYddvwxnNty23BeaKzh7YuoSIvIMO4jEhvw,87
106
+ python_codex-0.7.2.dist-info/entry_points.txt,sha256=sNUVakoVuTrzJH505ZgRTQxmtRRPUHV_EH0i6EbYTyM,45
107
+ python_codex-0.7.2.dist-info/licenses/LICENSE,sha256=0X8ifk312hYAORM4hlzg8wVSEXYKNmiPgWlB1YIy2Nw,10926
108
+ python_codex-0.7.2.dist-info/RECORD,,