swegen 0.1.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.
- swegen/__init__.py +14 -0
- swegen/analyze/__init__.py +24 -0
- swegen/analyze/classifier.py +637 -0
- swegen/analyze/classify_prompt.txt +241 -0
- swegen/analyze/models.py +253 -0
- swegen/analyze/run.py +656 -0
- swegen/analyze/verdict_prompt.txt +126 -0
- swegen/cli.py +411 -0
- swegen/config.py +142 -0
- swegen/create/__init__.py +22 -0
- swegen/create/claude_code_runner.py +988 -0
- swegen/create/claude_code_utils.py +95 -0
- swegen/create/create.py +706 -0
- swegen/create/diff_utils.py +142 -0
- swegen/create/orchestrator.py +368 -0
- swegen/create/pr_fetcher.py +187 -0
- swegen/create/repo_cache.py +175 -0
- swegen/create/task_instruction.py +363 -0
- swegen/create/task_reference.py +130 -0
- swegen/create/task_skeleton.py +266 -0
- swegen/create/utils.py +350 -0
- swegen/farm/__init__.py +13 -0
- swegen/farm/farm_hand.py +342 -0
- swegen/farm/fetcher.py +341 -0
- swegen/farm/state.py +231 -0
- swegen/farm/stream_farm.py +430 -0
- swegen/tools/__init__.py +16 -0
- swegen/tools/harbor_runner.py +191 -0
- swegen/tools/validate.py +523 -0
- swegen/tools/validate_utils.py +142 -0
- swegen-0.1.0.dist-info/METADATA +292 -0
- swegen-0.1.0.dist-info/RECORD +35 -0
- swegen-0.1.0.dist-info/WHEEL +4 -0
- swegen-0.1.0.dist-info/entry_points.txt +3 -0
- swegen-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from claude_agent_sdk import (
|
|
4
|
+
AssistantMessage,
|
|
5
|
+
ResultMessage,
|
|
6
|
+
SystemMessage,
|
|
7
|
+
TextBlock,
|
|
8
|
+
ToolResultBlock,
|
|
9
|
+
ToolUseBlock,
|
|
10
|
+
UserMessage,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# ANSI color codes for verbose output
|
|
15
|
+
class Colors:
|
|
16
|
+
BLUE = "\033[94m" # Assistant messages
|
|
17
|
+
CYAN = "\033[96m" # Tool use
|
|
18
|
+
MAGENTA = "\033[95m" # Tool results
|
|
19
|
+
GREEN = "\033[92m" # Success/final result
|
|
20
|
+
YELLOW = "\033[93m" # System messages
|
|
21
|
+
RED = "\033[91m" # Errors
|
|
22
|
+
BOLD = "\033[1m"
|
|
23
|
+
RESET = "\033[0m"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def print_sdk_message(message: object) -> None:
|
|
27
|
+
"""Print SDK messages with colored formatting.
|
|
28
|
+
|
|
29
|
+
Message types include:
|
|
30
|
+
- AssistantMessage: Claude's text responses and tool uses
|
|
31
|
+
- UserMessage: User messages (for tool results in SDK)
|
|
32
|
+
- ResultMessage: Final result message
|
|
33
|
+
- SystemMessage: System notifications
|
|
34
|
+
"""
|
|
35
|
+
if isinstance(message, AssistantMessage):
|
|
36
|
+
# Assistant message content
|
|
37
|
+
for block in message.content:
|
|
38
|
+
if isinstance(block, TextBlock):
|
|
39
|
+
text = block.text
|
|
40
|
+
if text.strip():
|
|
41
|
+
print(f"\n{Colors.BLUE}[Assistant]{Colors.RESET} {text}", flush=True)
|
|
42
|
+
elif isinstance(block, ToolUseBlock):
|
|
43
|
+
tool_name = block.name.upper()
|
|
44
|
+
tool_input = block.input
|
|
45
|
+
# Less aggressive truncation - commands are important!
|
|
46
|
+
summary: dict | str
|
|
47
|
+
if isinstance(tool_input, dict):
|
|
48
|
+
# For bash commands, show up to 2000 chars; for other inputs, 1000 chars
|
|
49
|
+
max_len = 2000 if tool_name.lower() == "bash" else 1000
|
|
50
|
+
summary = {
|
|
51
|
+
k: (
|
|
52
|
+
v[:max_len] + "..."
|
|
53
|
+
if isinstance(v, str) and len(v) > max_len
|
|
54
|
+
else v
|
|
55
|
+
)
|
|
56
|
+
for k, v in tool_input.items()
|
|
57
|
+
}
|
|
58
|
+
else:
|
|
59
|
+
summary = str(tool_input)[:2000]
|
|
60
|
+
print(
|
|
61
|
+
f"\n{Colors.CYAN}{Colors.BOLD}{tool_name}{Colors.RESET}: {summary}",
|
|
62
|
+
flush=True,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
elif isinstance(message, UserMessage):
|
|
66
|
+
# In SDK mode, tool results come as UserMessage with ToolResultBlock
|
|
67
|
+
for block in message.content:
|
|
68
|
+
if isinstance(block, ToolResultBlock):
|
|
69
|
+
content = block.content if hasattr(block, "content") else str(block)
|
|
70
|
+
# Less aggressive truncation - show up to 2000 chars
|
|
71
|
+
if isinstance(content, str) and len(content) > 2000:
|
|
72
|
+
content = content[:2000] + f"... ({len(content)} chars total)"
|
|
73
|
+
print(f"{Colors.MAGENTA}[Tool Result]{Colors.RESET} {content}", flush=True)
|
|
74
|
+
elif isinstance(block, TextBlock):
|
|
75
|
+
text = block.text
|
|
76
|
+
if text.strip():
|
|
77
|
+
print(f"{Colors.MAGENTA}[Tool Result]{Colors.RESET} {text}", flush=True)
|
|
78
|
+
|
|
79
|
+
elif isinstance(message, ResultMessage):
|
|
80
|
+
# Final result message
|
|
81
|
+
result_text = getattr(message, "text", str(message))
|
|
82
|
+
if result_text and result_text.strip():
|
|
83
|
+
if len(result_text) > 3000:
|
|
84
|
+
result_text = result_text[:3000] + f"... ({len(result_text)} chars total)"
|
|
85
|
+
print(
|
|
86
|
+
f"\n{Colors.GREEN}{Colors.BOLD}[Final Result]{Colors.RESET}\n{result_text}",
|
|
87
|
+
flush=True,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
elif isinstance(message, SystemMessage):
|
|
91
|
+
# System messages
|
|
92
|
+
msg_text = getattr(message, "text", str(message))
|
|
93
|
+
if msg_text:
|
|
94
|
+
print(f"{Colors.YELLOW}[System]{Colors.RESET} {msg_text}", flush=True)
|
|
95
|
+
|