python-codex 0.5.2__py3-none-any.whl → 0.6.1__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.
- pycodex/__init__.py +22 -12
- pycodex/agent.py +89 -74
- pycodex/bootstrap.py +37 -251
- pycodex/cli.py +19 -28
- pycodex/config.py +36 -0
- pycodex/context.py +368 -51
- pycodex/events.py +14 -187
- pycodex/model.py +197 -95
- pycodex/multi_agents.py +401 -0
- pycodex/portable/__init__.py +8 -6
- pycodex/portable/client.py +24 -39
- pycodex/portable/protocol.py +28 -0
- pycodex/portable/server.py +3 -3
- pycodex/prompts/developer_messages.json +13 -0
- pycodex/prompts/goals/budget_limit.md +19 -0
- pycodex/prompts/goals/continuation.md +56 -0
- pycodex/prompts/models.json +1143 -200
- pycodex/protocol.py +81 -15
- pycodex/runtime.py +370 -226
- pycodex/tools/__init__.py +102 -10
- pycodex/tools/agent_tool_schemas.py +0 -38
- pycodex/tools/apply_patch_tool.py +17 -34
- pycodex/tools/base_tool.py +63 -35
- pycodex/tools/clock_manager.py +182 -0
- pycodex/tools/clock_tool.py +58 -187
- pycodex/tools/code_mode_manager.py +165 -246
- pycodex/tools/exec_command_tool.py +0 -18
- pycodex/tools/exec_runtime.py +332 -0
- pycodex/tools/exec_tool.py +74 -31
- pycodex/tools/followup_task_tool.py +44 -0
- pycodex/tools/goal_manager.py +205 -0
- pycodex/tools/goal_tool.py +126 -0
- pycodex/tools/interrupt_agent_tool.py +48 -0
- pycodex/tools/list_agents_tool.py +66 -0
- pycodex/tools/python_tool_schema.py +141 -0
- pycodex/tools/request_permissions_tool.py +1 -0
- pycodex/tools/runtime_services.py +122 -450
- pycodex/tools/send_message_tool.py +42 -0
- pycodex/tools/spawn_agent_tool.py +55 -94
- pycodex/tools/unified_exec_manager.py +26 -35
- pycodex/tools/wait_agent_tool.py +46 -66
- pycodex/tools/wait_tool.py +24 -13
- pycodex/tools/web_search_tool.py +1 -0
- pycodex/utils/codex_config.py +105 -0
- pycodex/utils/compactor.py +4 -0
- pycodex/utils/compat.py +43 -2
- pycodex/utils/doctor.py +5 -4
- pycodex/utils/dotenv.py +0 -7
- pycodex/utils/event_helpers.py +143 -13
- pycodex/utils/history.py +59 -0
- pycodex/utils/session_persist.py +104 -48
- python_codex-0.6.1.dist-info/METADATA +201 -0
- python_codex-0.6.1.dist-info/RECORD +106 -0
- responses_server/__init__.py +2 -0
- responses_server/app.py +10 -7
- responses_server/config.py +6 -12
- responses_server/gemini_api.py +333 -0
- responses_server/messages_api.py +9 -1
- responses_server/payload_processors.py +4 -4
- responses_server/request_translation.py +486 -0
- responses_server/server.py +31 -24
- responses_server/stream_events.py +124 -0
- responses_server/stream_router.py +48 -830
- responses_server/tools/custom_adapter.py +29 -29
- responses_server/tools/web_search.py +3 -0
- responses_server/transport.py +388 -0
- pycodex/tools/close_agent_tool.py +0 -60
- pycodex/tools/exec_runtime.js +0 -161
- pycodex/tools/request_user_input_tool.py +0 -102
- pycodex/tools/resume_agent_tool.py +0 -54
- pycodex/tools/send_input_tool.py +0 -110
- python_codex-0.5.2.dist-info/METADATA +0 -262
- python_codex-0.5.2.dist-info/RECORD +0 -90
- {python_codex-0.5.2.dist-info → python_codex-0.6.1.dist-info}/WHEEL +0 -0
- {python_codex-0.5.2.dist-info → python_codex-0.6.1.dist-info}/entry_points.txt +0 -0
- {python_codex-0.5.2.dist-info → python_codex-0.6.1.dist-info}/licenses/LICENSE +0 -0
pycodex/events.py
CHANGED
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
"""Typed events, plain-text views and stateful presentation without frontend I/O."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
-
import re
|
|
5
|
-
import shlex
|
|
6
4
|
import typing
|
|
7
5
|
from dataclasses import dataclass
|
|
8
6
|
from typing import ClassVar
|
|
9
7
|
|
|
10
8
|
from .protocol import JSONDict, ToolCall, ToolResult
|
|
11
9
|
from .utils.event_helpers import (
|
|
12
|
-
agent_status_summary,
|
|
13
10
|
colorize_cli_message,
|
|
14
11
|
colorize_tool_message,
|
|
15
12
|
compact_summary,
|
|
16
13
|
format_command_result,
|
|
17
14
|
format_error,
|
|
18
15
|
percent_of_context_window_remaining,
|
|
19
|
-
short_id,
|
|
20
16
|
shorten_title,
|
|
21
|
-
|
|
17
|
+
summarize_tool_result,
|
|
22
18
|
)
|
|
23
19
|
|
|
24
20
|
DEFAULT_MAIN_PROMPT = "pycodex> "
|
|
@@ -44,7 +40,6 @@ class EventDisplay:
|
|
|
44
40
|
self.stream_buffer = ""
|
|
45
41
|
self.queued_steer_prompts = {}
|
|
46
42
|
self.inserted_steer_prompts = {}
|
|
47
|
-
self.agent_names = {}
|
|
48
43
|
self.closed = False
|
|
49
44
|
self.set_context_window_tokens(context_window_tokens)
|
|
50
45
|
|
|
@@ -115,24 +110,6 @@ class EventDisplay:
|
|
|
115
110
|
return DEFAULT_MAIN_PROMPT
|
|
116
111
|
return f"pyco({self.context_remaining_percent}%)> "
|
|
117
112
|
|
|
118
|
-
def remember_agent_name(self, summary):
|
|
119
|
-
if " (" not in summary or not summary.endswith(")"):
|
|
120
|
-
return
|
|
121
|
-
nickname, rest = summary.rsplit(" (", 1)
|
|
122
|
-
agent_short_id = rest[:-1].strip()
|
|
123
|
-
nickname = nickname.strip()
|
|
124
|
-
if nickname and agent_short_id:
|
|
125
|
-
self.agent_names[agent_short_id] = nickname
|
|
126
|
-
|
|
127
|
-
def replace_agent_ids_with_names(self, message):
|
|
128
|
-
for agent_short_id, nickname in sorted(
|
|
129
|
-
self.agent_names.items(),
|
|
130
|
-
key=lambda item: len(item[0]),
|
|
131
|
-
reverse=True,
|
|
132
|
-
):
|
|
133
|
-
message = message.replace(agent_short_id, nickname)
|
|
134
|
-
return message
|
|
135
|
-
|
|
136
113
|
@staticmethod
|
|
137
114
|
def status_frame(text, frame_index):
|
|
138
115
|
if text is None:
|
|
@@ -181,6 +158,15 @@ class TurnStartedEvent(TurnEvent):
|
|
|
181
158
|
display.begin_turn(self)
|
|
182
159
|
|
|
183
160
|
|
|
161
|
+
@dataclass(frozen=True)
|
|
162
|
+
class TurnInputReadyEvent(TurnEvent):
|
|
163
|
+
"""Synchronous input coordination; delivery failures must fail the turn."""
|
|
164
|
+
|
|
165
|
+
turn_id: "str"
|
|
166
|
+
submission_id: "typing.Union[str, None]" = None
|
|
167
|
+
kind: ClassVar[str] = "turn_input_ready"
|
|
168
|
+
|
|
169
|
+
|
|
184
170
|
@dataclass(frozen=True)
|
|
185
171
|
class TurnCompletedEvent(TerminalEvent):
|
|
186
172
|
turn_id: "str"
|
|
@@ -379,20 +365,12 @@ class ToolCompletedEvent(TurnEvent):
|
|
|
379
365
|
message = self.visualize()
|
|
380
366
|
if name:
|
|
381
367
|
display.set_status("called " + name)
|
|
382
|
-
if name in {"wait_agent", "send_input", "resume_agent", "close_agent"}:
|
|
383
|
-
message = display.replace_agent_ids_with_names(message)
|
|
384
|
-
if name == "spawn_agent":
|
|
385
|
-
summary = message
|
|
386
|
-
prefix = "[spawn_agent] spawned "
|
|
387
|
-
if summary.startswith(prefix):
|
|
388
|
-
summary = summary[len(prefix) :]
|
|
389
|
-
display.remember_agent_name(summary)
|
|
390
368
|
for line in message.splitlines() or [""]:
|
|
391
369
|
display.log(colorize_tool_message(line, display.color_enabled, name))
|
|
392
370
|
|
|
393
371
|
def visualize(self) -> "str":
|
|
394
372
|
name = self.call.name
|
|
395
|
-
summary = self.
|
|
373
|
+
summary = summarize_tool_result(self.call, self.result)
|
|
396
374
|
if self.result.is_error:
|
|
397
375
|
return f"[error] {name} failed" + (f": {summary}" if summary else "")
|
|
398
376
|
if name == "spawn_agent":
|
|
@@ -420,159 +398,6 @@ class ToolCompletedEvent(TurnEvent):
|
|
|
420
398
|
return "\n".join(lines)
|
|
421
399
|
return f"[{name}]" + (f" {summary}" if summary else "")
|
|
422
400
|
|
|
423
|
-
def _summary(self) -> "str":
|
|
424
|
-
name = self.call.name
|
|
425
|
-
arguments = self.call.arguments if isinstance(self.call.arguments, dict) else {}
|
|
426
|
-
output = self.result.output
|
|
427
|
-
call_summary = ""
|
|
428
|
-
result_summary = None
|
|
429
|
-
if name == "exec_command":
|
|
430
|
-
command = arguments.get("cmd")
|
|
431
|
-
if command not in (None, ""):
|
|
432
|
-
command = str(command)
|
|
433
|
-
call_summary = truncate_text(command, 200)
|
|
434
|
-
lines = command.splitlines()
|
|
435
|
-
match = re.search(
|
|
436
|
-
r"\bpython(?:\d+(?:\.\d+)?)?\s+-\s+<<[-]?\s*(['\"]?)([A-Za-z_][A-Za-z0-9_]*)\1",
|
|
437
|
-
lines[0] if lines else "",
|
|
438
|
-
)
|
|
439
|
-
if match is not None:
|
|
440
|
-
for index, line in enumerate(lines[1:], 1):
|
|
441
|
-
if line.strip() == match.group(2):
|
|
442
|
-
call_summary = "\n".join(lines[: index + 1])
|
|
443
|
-
break
|
|
444
|
-
marker = "Process running with session ID "
|
|
445
|
-
for line in self.result.output_text().splitlines():
|
|
446
|
-
line = line.strip()
|
|
447
|
-
if line.startswith(marker) and line[len(marker) :].strip():
|
|
448
|
-
result_summary = "session_id=" + line[len(marker) :].strip()
|
|
449
|
-
break
|
|
450
|
-
elif name == "shell_command":
|
|
451
|
-
command = arguments.get("command")
|
|
452
|
-
if command not in (None, ""):
|
|
453
|
-
call_summary = truncate_text(str(command), 200)
|
|
454
|
-
elif name == "shell":
|
|
455
|
-
command = arguments.get("command")
|
|
456
|
-
if isinstance(command, list) and command:
|
|
457
|
-
call_summary = truncate_text(
|
|
458
|
-
" ".join(shlex.quote(str(part)) for part in command), 200
|
|
459
|
-
)
|
|
460
|
-
elif name == "write_stdin":
|
|
461
|
-
session_id = arguments.get("session_id")
|
|
462
|
-
if session_id not in (None, ""):
|
|
463
|
-
session_id = str(session_id)
|
|
464
|
-
chars = arguments.get("chars") or ""
|
|
465
|
-
call_summary = (
|
|
466
|
-
f"session {session_id} <- {truncate_text(str(chars), 32)}"
|
|
467
|
-
if chars
|
|
468
|
-
else f"poll session {session_id}"
|
|
469
|
-
)
|
|
470
|
-
elif name in {"read_file", "list_dir", "view_image"}:
|
|
471
|
-
key = (
|
|
472
|
-
"file_path"
|
|
473
|
-
if name == "read_file"
|
|
474
|
-
else ("dir_path" if name == "list_dir" else "path")
|
|
475
|
-
)
|
|
476
|
-
path = arguments.get(key)
|
|
477
|
-
if path not in (None, ""):
|
|
478
|
-
call_summary = truncate_text(str(path), 200)
|
|
479
|
-
if name == "view_image" and isinstance(output, list):
|
|
480
|
-
result_summary = f"{len(output)} image item(s)"
|
|
481
|
-
elif name == "grep_files":
|
|
482
|
-
pattern, path = arguments.get("pattern"), arguments.get("path")
|
|
483
|
-
if pattern not in (None, ""):
|
|
484
|
-
call_summary = truncate_text(
|
|
485
|
-
f"{pattern} @ {path}" if path not in (None, "") else str(pattern),
|
|
486
|
-
200,
|
|
487
|
-
)
|
|
488
|
-
elif name == "update_plan":
|
|
489
|
-
plan = arguments.get("plan")
|
|
490
|
-
if isinstance(plan, list):
|
|
491
|
-
total = len(plan)
|
|
492
|
-
completed = 0
|
|
493
|
-
in_progress = 0
|
|
494
|
-
for item in plan:
|
|
495
|
-
if isinstance(item, dict):
|
|
496
|
-
status = str(item.get("status", "")).strip()
|
|
497
|
-
completed += status == "completed"
|
|
498
|
-
in_progress += status == "in_progress"
|
|
499
|
-
if not total:
|
|
500
|
-
return "0 steps"
|
|
501
|
-
if completed >= total:
|
|
502
|
-
return f"Done {completed}/{total}"
|
|
503
|
-
if in_progress:
|
|
504
|
-
return f"Working on {completed + in_progress}/{total}"
|
|
505
|
-
return f"Planned {completed}/{total}"
|
|
506
|
-
if isinstance(output, dict) and isinstance(output.get("plan"), list):
|
|
507
|
-
return f"{len(output['plan'])} steps"
|
|
508
|
-
elif name == "spawn_agent":
|
|
509
|
-
if isinstance(output, dict):
|
|
510
|
-
agent_id = str(output.get("agent_id", "")).strip()
|
|
511
|
-
nickname = str(output.get("nickname", "")).strip()
|
|
512
|
-
if nickname and agent_id:
|
|
513
|
-
return f"{nickname} ({short_id(agent_id)})"
|
|
514
|
-
elif name == "send_input":
|
|
515
|
-
agent_id, message = arguments.get("id"), arguments.get("message")
|
|
516
|
-
prefix = f"{short_id(str(agent_id))} <- " if agent_id else ""
|
|
517
|
-
call_summary = (
|
|
518
|
-
prefix + truncate_text(str(message), 40)
|
|
519
|
-
if message not in (None, "")
|
|
520
|
-
else prefix.rstrip()
|
|
521
|
-
)
|
|
522
|
-
if isinstance(output, dict):
|
|
523
|
-
submission_id = str(output.get("submission_id", "")).strip()
|
|
524
|
-
if submission_id:
|
|
525
|
-
result_summary = "queued " + short_id(submission_id)
|
|
526
|
-
elif name == "wait_agent":
|
|
527
|
-
if isinstance(output, dict):
|
|
528
|
-
if output.get("timed_out") is True:
|
|
529
|
-
return "timed out"
|
|
530
|
-
status = output.get("status")
|
|
531
|
-
if isinstance(status, dict):
|
|
532
|
-
parts = [
|
|
533
|
-
f"{short_id(agent_id)}={agent_status_summary(agent_status)}"
|
|
534
|
-
for agent_id, agent_status in status.items()
|
|
535
|
-
if isinstance(agent_id, str)
|
|
536
|
-
]
|
|
537
|
-
if parts:
|
|
538
|
-
return truncate_text(", ".join(parts))
|
|
539
|
-
elif name in {"resume_agent", "close_agent"}:
|
|
540
|
-
agent_id = arguments.get("id")
|
|
541
|
-
if agent_id not in (None, ""):
|
|
542
|
-
call_summary = short_id(str(agent_id))
|
|
543
|
-
if isinstance(output, dict):
|
|
544
|
-
result_summary = agent_status_summary(output.get("status"))
|
|
545
|
-
if result_summary is None:
|
|
546
|
-
if isinstance(output, (dict, list)):
|
|
547
|
-
result_summary = truncate_text(
|
|
548
|
-
json.dumps(output, ensure_ascii=False, separators=(",", ":"))
|
|
549
|
-
)
|
|
550
|
-
else:
|
|
551
|
-
lines = [
|
|
552
|
-
line.strip() for line in self.result.output_text().splitlines()
|
|
553
|
-
]
|
|
554
|
-
if "Output:" in lines:
|
|
555
|
-
result_summary = next(
|
|
556
|
-
(line for line in lines[lines.index("Output:") + 1 :] if line),
|
|
557
|
-
None,
|
|
558
|
-
)
|
|
559
|
-
if result_summary is None:
|
|
560
|
-
result_summary = next(
|
|
561
|
-
(
|
|
562
|
-
line
|
|
563
|
-
for line in lines
|
|
564
|
-
if line
|
|
565
|
-
and not line.startswith(
|
|
566
|
-
("Exit code:", "Wall time:", "Command:")
|
|
567
|
-
)
|
|
568
|
-
),
|
|
569
|
-
"",
|
|
570
|
-
)
|
|
571
|
-
result_summary = truncate_text(result_summary)
|
|
572
|
-
if call_summary and result_summary:
|
|
573
|
-
return f"{call_summary} -> {result_summary}"
|
|
574
|
-
return call_summary or result_summary
|
|
575
|
-
|
|
576
401
|
|
|
577
402
|
@dataclass(frozen=True)
|
|
578
403
|
class CompactStartedEvent(TurnEvent):
|
|
@@ -745,6 +570,8 @@ class SessionStateEvent(Event):
|
|
|
745
570
|
active["submission_id"],
|
|
746
571
|
).render(display)
|
|
747
572
|
display.stream_buffer = active["assistant_text"]
|
|
573
|
+
elif not state["busy"]:
|
|
574
|
+
display.set_idle_status(state["background_work_count"])
|
|
748
575
|
if self.reason == "auto_title":
|
|
749
576
|
display.show_title()
|
|
750
577
|
if self.reason == "attach" and state["input_request"] is not None:
|
|
@@ -871,7 +698,7 @@ class InputRequestedEvent(Event):
|
|
|
871
698
|
question = self.question
|
|
872
699
|
return "\n".join(
|
|
873
700
|
[
|
|
874
|
-
"[
|
|
701
|
+
"[input] waiting for user response",
|
|
875
702
|
"[{0}] {1}".format(question["header"], question["question"]),
|
|
876
703
|
]
|
|
877
704
|
+ [
|