python-codex 0.5.1__py3-none-any.whl → 0.6.0__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.
Files changed (72) hide show
  1. pycodex/__init__.py +18 -8
  2. pycodex/agent.py +89 -74
  3. pycodex/bootstrap.py +27 -239
  4. pycodex/cli.py +19 -14
  5. pycodex/config.py +36 -0
  6. pycodex/context.py +369 -51
  7. pycodex/events.py +28 -186
  8. pycodex/model.py +181 -88
  9. pycodex/multi_agents.py +401 -0
  10. pycodex/portable/__init__.py +8 -6
  11. pycodex/portable/client.py +24 -39
  12. pycodex/portable/protocol.py +28 -0
  13. pycodex/portable/server.py +3 -3
  14. pycodex/prompts/developer_messages.json +13 -0
  15. pycodex/prompts/goals/budget_limit.md +19 -0
  16. pycodex/prompts/goals/continuation.md +56 -0
  17. pycodex/prompts/models.json +1069 -140
  18. pycodex/protocol.py +78 -15
  19. pycodex/runtime.py +461 -203
  20. pycodex/tools/__init__.py +100 -7
  21. pycodex/tools/agent_tool_schemas.py +0 -38
  22. pycodex/tools/apply_patch_tool.py +17 -34
  23. pycodex/tools/base_tool.py +63 -29
  24. pycodex/tools/clock_manager.py +182 -0
  25. pycodex/tools/clock_tool.py +2 -139
  26. pycodex/tools/code_mode_manager.py +165 -246
  27. pycodex/tools/exec_command_tool.py +0 -12
  28. pycodex/tools/exec_runtime.py +381 -0
  29. pycodex/tools/exec_tool.py +78 -31
  30. pycodex/tools/followup_task_tool.py +44 -0
  31. pycodex/tools/goal_manager.py +205 -0
  32. pycodex/tools/goal_tool.py +126 -0
  33. pycodex/tools/interrupt_agent_tool.py +48 -0
  34. pycodex/tools/list_agents_tool.py +66 -0
  35. pycodex/tools/python_tool_schema.py +141 -0
  36. pycodex/tools/request_permissions_tool.py +1 -0
  37. pycodex/tools/request_user_input_tool.py +3 -23
  38. pycodex/tools/runtime_services.py +124 -408
  39. pycodex/tools/send_message_tool.py +42 -0
  40. pycodex/tools/spawn_agent_tool.py +55 -94
  41. pycodex/tools/unified_exec_manager.py +52 -34
  42. pycodex/tools/wait_agent_tool.py +46 -66
  43. pycodex/tools/wait_tool.py +24 -13
  44. pycodex/tools/web_search_tool.py +1 -0
  45. pycodex/utils/codex_config.py +105 -0
  46. pycodex/utils/compactor.py +4 -0
  47. pycodex/utils/compat.py +2 -2
  48. pycodex/utils/doctor.py +5 -4
  49. pycodex/utils/event_helpers.py +143 -13
  50. pycodex/utils/history.py +33 -0
  51. pycodex/utils/session_persist.py +106 -33
  52. python_codex-0.6.0.dist-info/METADATA +352 -0
  53. python_codex-0.6.0.dist-info/RECORD +106 -0
  54. responses_server/__init__.py +2 -0
  55. responses_server/app.py +7 -6
  56. responses_server/config.py +0 -11
  57. responses_server/payload_processors.py +4 -4
  58. responses_server/request_translation.py +480 -0
  59. responses_server/server.py +31 -24
  60. responses_server/stream_events.py +124 -0
  61. responses_server/stream_router.py +33 -830
  62. responses_server/tools/custom_adapter.py +29 -29
  63. responses_server/transport.py +332 -0
  64. pycodex/tools/close_agent_tool.py +0 -60
  65. pycodex/tools/exec_runtime.js +0 -161
  66. pycodex/tools/resume_agent_tool.py +0 -54
  67. pycodex/tools/send_input_tool.py +0 -110
  68. python_codex-0.5.1.dist-info/METADATA +0 -235
  69. python_codex-0.5.1.dist-info/RECORD +0 -90
  70. {python_codex-0.5.1.dist-info → python_codex-0.6.0.dist-info}/WHEEL +0 -0
  71. {python_codex-0.5.1.dist-info → python_codex-0.6.0.dist-info}/entry_points.txt +0 -0
  72. {python_codex-0.5.1.dist-info → python_codex-0.6.0.dist-info}/licenses/LICENSE +0 -0
@@ -5,20 +5,9 @@ clock starts counting only after the Agent completes a reply. Every new turn
5
5
  cancels the pending countdown, and every successful reply starts a fresh one.
6
6
  """
7
7
 
8
- import asyncio
9
- import math
10
- import typing
11
- from datetime import datetime
12
-
13
- from ..events import (
14
- CompactCompletedEvent,
15
- CompactStartedEvent,
16
- Event,
17
- TurnCompletedEvent,
18
- TurnStartedEvent,
19
- )
20
8
  from ..protocol import JSONDict, JSONValue
21
9
  from .base_tool import BaseTool, ToolContext
10
+ from .clock_manager import ClockManager
22
11
 
23
12
  CLOCK_STATE_OUTPUT_SCHEMA = {
24
13
  "type": "object",
@@ -40,118 +29,8 @@ CLOCK_STATE_OUTPUT_SCHEMA = {
40
29
  }
41
30
 
42
31
 
43
- def _current_time() -> "str":
44
- return datetime.now().astimezone().isoformat(timespec="seconds")
45
-
46
-
47
- class ClockManager:
48
- def __init__(self, seconds_per_minute: "float" = 60.0) -> "None":
49
- self._seconds_per_minute = seconds_per_minute
50
- self._period_m: "typing.Union[float, None]" = None
51
- self._timer_task: "typing.Union[asyncio.Task, None]" = None
52
- self._generation = 0
53
- self._notify_hook: "typing.Union[typing.Callable[[typing.Dict[str, object]], typing.Awaitable[typing.Any]], None]" = (None)
54
-
55
- def set_notify_hook(
56
- self,
57
- callback: "typing.Union[typing.Callable[[typing.Dict[str, object]], typing.Awaitable[typing.Any]], None]",
58
- ) -> "None":
59
- self._notify_hook = callback
60
-
61
- def set_period(self, value: "object") -> "JSONDict":
62
- self._cancel_pending()
63
- if value is None:
64
- self._period_m = None
65
- return self.snapshot()
66
- if isinstance(value, bool) or not isinstance(value, (int, float)):
67
- raise ValueError("period_m must be a positive finite number or null")
68
- period_m = float(value)
69
- if not math.isfinite(period_m) or period_m <= 0:
70
- raise ValueError("period_m must be a positive finite number or null")
71
- self._period_m = period_m
72
- return self.snapshot()
73
-
74
- def snapshot(self) -> "JSONDict":
75
- return {
76
- "enabled": self.enabled,
77
- "period_m": self._period_m,
78
- }
79
-
80
- @property
81
- def enabled(self) -> "bool":
82
- return self._period_m is not None
83
-
84
- def turn_started(self) -> "None":
85
- self._cancel_pending()
86
-
87
- def arm_after_reply(self) -> "None":
88
- self._cancel_pending()
89
- period_m = self._period_m
90
- if period_m is None or self._notify_hook is None:
91
- return
92
- generation = self._generation
93
- self._timer_task = asyncio.create_task(
94
- self._wait_and_notify(generation, period_m)
95
- )
96
- self._timer_task.add_done_callback(
97
- lambda task: None if task.cancelled() else task.exception()
98
- )
99
-
100
- def cancel(self) -> "None":
101
- self.set_period(None)
102
-
103
- def _cancel_pending(self) -> "None":
104
- self._generation += 1
105
- task = self._timer_task
106
- self._timer_task = None
107
- if task is not None and not task.done():
108
- task.cancel()
109
-
110
- async def _wait_and_notify(self, generation: "int", period_m: "float") -> "None":
111
- from ..agent import TurnInterrupted
112
-
113
- try:
114
- await asyncio.sleep(period_m * self._seconds_per_minute)
115
- except asyncio.CancelledError:
116
- return
117
- if generation != self._generation or period_m != self._period_m:
118
- return
119
-
120
- self._timer_task = None
121
- callback = self._notify_hook
122
- if callback is None:
123
- return
124
- try:
125
- started = await callback(
126
- {
127
- "type": "clock_tick",
128
- "period_m": period_m,
129
- "current_time": _current_time(),
130
- }
131
- )
132
- except TurnInterrupted:
133
- # The next successful reply will arm the clock after a steer.
134
- return
135
- except asyncio.CancelledError:
136
- raise
137
- except Exception as exc:
138
- asyncio.get_running_loop().call_exception_handler(
139
- {
140
- "message": "Clock notification failed",
141
- "exception": exc,
142
- }
143
- )
144
- return
145
-
146
- if (
147
- not started
148
- and generation == self._generation
149
- and period_m == self._period_m
150
- ):
151
- self.arm_after_reply()
152
-
153
-
154
32
  class ClockTool(BaseTool):
33
+ exec_only = False
155
34
  name = "clock"
156
35
  description = (
157
36
  "Set a periodic clock in minutes, or cancel it with null. After each "
@@ -178,22 +57,6 @@ class ClockTool(BaseTool):
178
57
  def __init__(self, manager: "ClockManager") -> "None":
179
58
  self._manager = manager
180
59
 
181
- def bind_agent(self, agent) -> "None":
182
- self._manager.set_notify_hook(agent.maybe_invoke)
183
-
184
- def handle_agent_event(self, event: "Event") -> "None":
185
- if isinstance(event, (TurnStartedEvent, CompactStartedEvent)):
186
- self._manager.turn_started()
187
- elif isinstance(event, (TurnCompletedEvent, CompactCompletedEvent)):
188
- self._manager.arm_after_reply()
189
-
190
- def shutdown(self) -> "None":
191
- self._manager.cancel()
192
- self._manager.set_notify_hook(None)
193
-
194
- def background_work_count(self, after_reply: "bool") -> "int":
195
- return int(after_reply and self._manager.enabled)
196
-
197
60
  async def run(self, context: "ToolContext", args: "JSONDict") -> "JSONValue":
198
61
  del context
199
62
  if not isinstance(args, dict) or "period_m" not in args: