deepcode-hku 1.0.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.
- cli/__init__.py +18 -0
- cli/cli_app.py +296 -0
- cli/cli_interface.py +744 -0
- cli/cli_launcher.py +155 -0
- cli/main_cli.py +243 -0
- cli/workflows/__init__.py +11 -0
- cli/workflows/cli_workflow_adapter.py +336 -0
- deepcode.py +219 -0
- deepcode_hku-1.0.1.dist-info/METADATA +695 -0
- deepcode_hku-1.0.1.dist-info/RECORD +44 -0
- deepcode_hku-1.0.1.dist-info/WHEEL +5 -0
- deepcode_hku-1.0.1.dist-info/entry_points.txt +2 -0
- deepcode_hku-1.0.1.dist-info/licenses/LICENSE +21 -0
- deepcode_hku-1.0.1.dist-info/top_level.txt +6 -0
- tools/__init__.py +0 -0
- tools/code_implementation_server.py +1045 -0
- tools/code_indexer.py +1657 -0
- tools/code_reference_indexer.py +486 -0
- tools/command_executor.py +324 -0
- tools/git_command.py +356 -0
- tools/pdf_converter.py +640 -0
- tools/pdf_downloader.py +1370 -0
- tools/pdf_utils.py +52 -0
- ui/__init__.py +43 -0
- ui/app.py +13 -0
- ui/components.py +1450 -0
- ui/handlers.py +773 -0
- ui/layout.py +106 -0
- ui/streamlit_app.py +38 -0
- ui/styles.py +2116 -0
- utils/__init__.py +17 -0
- utils/cli_interface.py +459 -0
- utils/dialogue_logger.py +671 -0
- utils/file_processor.py +426 -0
- utils/simple_llm_logger.py +198 -0
- workflows/__init__.py +31 -0
- workflows/agent_orchestration_engine.py +1371 -0
- workflows/agents/__init__.py +13 -0
- workflows/agents/code_implementation_agent.py +1093 -0
- workflows/agents/memory_agent_concise.py +923 -0
- workflows/agents/memory_agent_concise_index.py +935 -0
- workflows/code_implementation_workflow.py +924 -0
- workflows/code_implementation_workflow_index.py +931 -0
- workflows/codebase_index_workflow.py +726 -0
cli/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
CLI Module for DeepCode Agent
|
|
3
|
+
DeepCode智能体CLI模块
|
|
4
|
+
|
|
5
|
+
包含以下组件 / Contains the following components:
|
|
6
|
+
- cli_app: CLI应用主程序 / CLI application main program
|
|
7
|
+
- cli_interface: CLI界面组件 / CLI interface components
|
|
8
|
+
- cli_launcher: CLI启动器 / CLI launcher
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "1.0.0"
|
|
12
|
+
__author__ = "DeepCode Team - Data Intelligence Lab @ HKU"
|
|
13
|
+
|
|
14
|
+
from .cli_app import main as cli_main
|
|
15
|
+
from .cli_interface import CLIInterface
|
|
16
|
+
from .cli_launcher import main as launcher_main
|
|
17
|
+
|
|
18
|
+
__all__ = ["cli_main", "CLIInterface", "launcher_main"]
|
cli/cli_app.py
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
DeepCode - CLI Application Main Program
|
|
4
|
+
深度代码 - CLI应用主程序
|
|
5
|
+
|
|
6
|
+
🧬 Open-Source Code Agent by Data Intelligence Lab @ HKU
|
|
7
|
+
⚡ Revolutionizing research reproducibility through collaborative AI
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
import asyncio
|
|
13
|
+
import time
|
|
14
|
+
import json
|
|
15
|
+
|
|
16
|
+
# 禁止生成.pyc文件
|
|
17
|
+
os.environ["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
18
|
+
|
|
19
|
+
# 添加项目根目录到路径
|
|
20
|
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
21
|
+
parent_dir = os.path.dirname(current_dir)
|
|
22
|
+
if parent_dir not in sys.path:
|
|
23
|
+
sys.path.insert(0, parent_dir)
|
|
24
|
+
|
|
25
|
+
# 导入MCP应用和工作流
|
|
26
|
+
|
|
27
|
+
from cli.workflows import CLIWorkflowAdapter
|
|
28
|
+
from cli.cli_interface import CLIInterface, Colors
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class CLIApp:
|
|
32
|
+
"""CLI应用主类 - 升级版智能体编排引擎"""
|
|
33
|
+
|
|
34
|
+
def __init__(self):
|
|
35
|
+
self.cli = CLIInterface()
|
|
36
|
+
self.workflow_adapter = CLIWorkflowAdapter(cli_interface=self.cli)
|
|
37
|
+
self.app = None # Will be initialized by workflow adapter
|
|
38
|
+
self.logger = None
|
|
39
|
+
self.context = None
|
|
40
|
+
|
|
41
|
+
async def initialize_mcp_app(self):
|
|
42
|
+
"""初始化MCP应用 - 使用工作流适配器"""
|
|
43
|
+
# Workflow adapter will handle MCP initialization
|
|
44
|
+
return await self.workflow_adapter.initialize_mcp_app()
|
|
45
|
+
|
|
46
|
+
async def cleanup_mcp_app(self):
|
|
47
|
+
"""清理MCP应用 - 使用工作流适配器"""
|
|
48
|
+
await self.workflow_adapter.cleanup_mcp_app()
|
|
49
|
+
|
|
50
|
+
async def process_input(self, input_source: str, input_type: str):
|
|
51
|
+
"""处理输入源(URL或文件)- 使用升级版智能体编排引擎"""
|
|
52
|
+
try:
|
|
53
|
+
self.cli.print_separator()
|
|
54
|
+
self.cli.print_status(
|
|
55
|
+
"🚀 Starting intelligent agent orchestration...", "processing"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# 显示处理阶段(根据配置决定)
|
|
59
|
+
self.cli.display_processing_stages(0, self.cli.enable_indexing)
|
|
60
|
+
|
|
61
|
+
# 使用工作流适配器进行处理
|
|
62
|
+
result = await self.workflow_adapter.process_input_with_orchestration(
|
|
63
|
+
input_source=input_source,
|
|
64
|
+
input_type=input_type,
|
|
65
|
+
enable_indexing=self.cli.enable_indexing,
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
if result["status"] == "success":
|
|
69
|
+
# 显示完成状态
|
|
70
|
+
final_stage = 8 if self.cli.enable_indexing else 5
|
|
71
|
+
self.cli.display_processing_stages(
|
|
72
|
+
final_stage, self.cli.enable_indexing
|
|
73
|
+
)
|
|
74
|
+
self.cli.print_status(
|
|
75
|
+
"🎉 Agent orchestration completed successfully!", "complete"
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# 显示结果
|
|
79
|
+
self.display_results(
|
|
80
|
+
result.get("analysis_result", ""),
|
|
81
|
+
result.get("download_result", ""),
|
|
82
|
+
result.get("repo_result", ""),
|
|
83
|
+
result.get("pipeline_mode", "comprehensive"),
|
|
84
|
+
)
|
|
85
|
+
else:
|
|
86
|
+
self.cli.print_status(
|
|
87
|
+
f"❌ Processing failed: {result.get('error', 'Unknown error')}",
|
|
88
|
+
"error",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# 添加到历史记录
|
|
92
|
+
self.cli.add_to_history(input_source, result)
|
|
93
|
+
|
|
94
|
+
return result
|
|
95
|
+
|
|
96
|
+
except Exception as e:
|
|
97
|
+
error_msg = str(e)
|
|
98
|
+
self.cli.print_error_box("Agent Orchestration Error", error_msg)
|
|
99
|
+
self.cli.print_status(f"Error during orchestration: {error_msg}", "error")
|
|
100
|
+
|
|
101
|
+
# 添加错误到历史记录
|
|
102
|
+
error_result = {"status": "error", "error": error_msg}
|
|
103
|
+
self.cli.add_to_history(input_source, error_result)
|
|
104
|
+
|
|
105
|
+
return error_result
|
|
106
|
+
|
|
107
|
+
def display_results(
|
|
108
|
+
self,
|
|
109
|
+
analysis_result: str,
|
|
110
|
+
download_result: str,
|
|
111
|
+
repo_result: str,
|
|
112
|
+
pipeline_mode: str = "comprehensive",
|
|
113
|
+
):
|
|
114
|
+
"""显示处理结果"""
|
|
115
|
+
self.cli.print_results_header()
|
|
116
|
+
|
|
117
|
+
# 显示流水线模式
|
|
118
|
+
if pipeline_mode == "chat":
|
|
119
|
+
mode_display = "💬 Chat Planning Mode"
|
|
120
|
+
elif pipeline_mode == "comprehensive":
|
|
121
|
+
mode_display = "🧠 Comprehensive Mode"
|
|
122
|
+
else:
|
|
123
|
+
mode_display = "⚡ Optimized Mode"
|
|
124
|
+
print(
|
|
125
|
+
f"{Colors.BOLD}{Colors.PURPLE}🤖 PIPELINE MODE: {mode_display}{Colors.ENDC}"
|
|
126
|
+
)
|
|
127
|
+
self.cli.print_separator("─", 79, Colors.PURPLE)
|
|
128
|
+
|
|
129
|
+
print(f"{Colors.BOLD}{Colors.OKCYAN}📊 ANALYSIS PHASE RESULTS:{Colors.ENDC}")
|
|
130
|
+
self.cli.print_separator("─", 79, Colors.CYAN)
|
|
131
|
+
|
|
132
|
+
# 尝试解析并格式化分析结果
|
|
133
|
+
try:
|
|
134
|
+
if analysis_result.strip().startswith("{"):
|
|
135
|
+
parsed_analysis = json.loads(analysis_result)
|
|
136
|
+
print(json.dumps(parsed_analysis, indent=2, ensure_ascii=False))
|
|
137
|
+
else:
|
|
138
|
+
print(
|
|
139
|
+
analysis_result[:1000] + "..."
|
|
140
|
+
if len(analysis_result) > 1000
|
|
141
|
+
else analysis_result
|
|
142
|
+
)
|
|
143
|
+
except Exception:
|
|
144
|
+
print(
|
|
145
|
+
analysis_result[:1000] + "..."
|
|
146
|
+
if len(analysis_result) > 1000
|
|
147
|
+
else analysis_result
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
print(f"\n{Colors.BOLD}{Colors.PURPLE}📥 DOWNLOAD PHASE RESULTS:{Colors.ENDC}")
|
|
151
|
+
self.cli.print_separator("─", 79, Colors.PURPLE)
|
|
152
|
+
print(
|
|
153
|
+
download_result[:1000] + "..."
|
|
154
|
+
if len(download_result) > 1000
|
|
155
|
+
else download_result
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
print(
|
|
159
|
+
f"\n{Colors.BOLD}{Colors.GREEN}⚙️ IMPLEMENTATION PHASE RESULTS:{Colors.ENDC}"
|
|
160
|
+
)
|
|
161
|
+
self.cli.print_separator("─", 79, Colors.GREEN)
|
|
162
|
+
print(repo_result[:1000] + "..." if len(repo_result) > 1000 else repo_result)
|
|
163
|
+
|
|
164
|
+
# 尝试提取生成的代码目录信息
|
|
165
|
+
if "Code generated in:" in repo_result:
|
|
166
|
+
code_dir = (
|
|
167
|
+
repo_result.split("Code generated in:")[-1].strip().split("\n")[0]
|
|
168
|
+
)
|
|
169
|
+
print(
|
|
170
|
+
f"\n{Colors.BOLD}{Colors.YELLOW}📁 Generated Code Directory: {Colors.ENDC}{code_dir}"
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
# 显示处理完成的工作流阶段
|
|
174
|
+
print(
|
|
175
|
+
f"\n{Colors.BOLD}{Colors.OKCYAN}🔄 COMPLETED WORKFLOW STAGES:{Colors.ENDC}"
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
if pipeline_mode == "chat":
|
|
179
|
+
stages = [
|
|
180
|
+
"🚀 Engine Initialization",
|
|
181
|
+
"💬 Requirements Analysis",
|
|
182
|
+
"🏗️ Workspace Setup",
|
|
183
|
+
"📝 Implementation Plan Generation",
|
|
184
|
+
"⚙️ Code Implementation",
|
|
185
|
+
]
|
|
186
|
+
else:
|
|
187
|
+
stages = [
|
|
188
|
+
"📄 Document Processing",
|
|
189
|
+
"🔍 Reference Analysis",
|
|
190
|
+
"📋 Plan Generation",
|
|
191
|
+
"📦 Repository Download",
|
|
192
|
+
"🗂️ Codebase Indexing",
|
|
193
|
+
"⚙️ Code Implementation",
|
|
194
|
+
]
|
|
195
|
+
|
|
196
|
+
for stage in stages:
|
|
197
|
+
print(f" ✅ {stage}")
|
|
198
|
+
|
|
199
|
+
self.cli.print_separator()
|
|
200
|
+
|
|
201
|
+
async def run_interactive_session(self):
|
|
202
|
+
"""运行交互式会话"""
|
|
203
|
+
# 清屏并显示启动界面
|
|
204
|
+
self.cli.clear_screen()
|
|
205
|
+
self.cli.print_logo()
|
|
206
|
+
self.cli.print_welcome_banner()
|
|
207
|
+
|
|
208
|
+
# 初始化MCP应用
|
|
209
|
+
await self.initialize_mcp_app()
|
|
210
|
+
|
|
211
|
+
try:
|
|
212
|
+
# 主交互循环
|
|
213
|
+
while self.cli.is_running:
|
|
214
|
+
self.cli.create_menu()
|
|
215
|
+
choice = self.cli.get_user_input()
|
|
216
|
+
|
|
217
|
+
if choice in ["q", "quit", "exit"]:
|
|
218
|
+
self.cli.print_goodbye()
|
|
219
|
+
break
|
|
220
|
+
|
|
221
|
+
elif choice in ["u", "url"]:
|
|
222
|
+
url = self.cli.get_url_input()
|
|
223
|
+
if url:
|
|
224
|
+
await self.process_input(url, "url")
|
|
225
|
+
|
|
226
|
+
elif choice in ["f", "file"]:
|
|
227
|
+
file_path = self.cli.upload_file_gui()
|
|
228
|
+
if file_path:
|
|
229
|
+
await self.process_input(f"file://{file_path}", "file")
|
|
230
|
+
|
|
231
|
+
elif choice in ["t", "chat", "text"]:
|
|
232
|
+
chat_input = self.cli.get_chat_input()
|
|
233
|
+
if chat_input:
|
|
234
|
+
await self.process_input(chat_input, "chat")
|
|
235
|
+
|
|
236
|
+
elif choice in ["h", "history"]:
|
|
237
|
+
self.cli.show_history()
|
|
238
|
+
|
|
239
|
+
elif choice in ["c", "config", "configure"]:
|
|
240
|
+
self.cli.show_configuration_menu()
|
|
241
|
+
|
|
242
|
+
else:
|
|
243
|
+
self.cli.print_status(
|
|
244
|
+
"Invalid choice. Please select U, F, T, C, H, or Q.", "warning"
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
# 询问是否继续
|
|
248
|
+
if self.cli.is_running and choice in ["u", "f", "t", "chat", "text"]:
|
|
249
|
+
if not self.cli.ask_continue():
|
|
250
|
+
self.cli.is_running = False
|
|
251
|
+
self.cli.print_status("Session ended by user", "info")
|
|
252
|
+
|
|
253
|
+
except KeyboardInterrupt:
|
|
254
|
+
print(f"\n{Colors.WARNING}⚠️ Process interrupted by user{Colors.ENDC}")
|
|
255
|
+
except Exception as e:
|
|
256
|
+
print(f"\n{Colors.FAIL}❌ Unexpected error: {str(e)}{Colors.ENDC}")
|
|
257
|
+
finally:
|
|
258
|
+
# 清理资源
|
|
259
|
+
await self.cleanup_mcp_app()
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
async def main():
|
|
263
|
+
"""主函数"""
|
|
264
|
+
start_time = time.time()
|
|
265
|
+
|
|
266
|
+
try:
|
|
267
|
+
# 创建并运行CLI应用
|
|
268
|
+
app = CLIApp()
|
|
269
|
+
await app.run_interactive_session()
|
|
270
|
+
|
|
271
|
+
except KeyboardInterrupt:
|
|
272
|
+
print(f"\n{Colors.WARNING}⚠️ Application interrupted by user{Colors.ENDC}")
|
|
273
|
+
except Exception as e:
|
|
274
|
+
print(f"\n{Colors.FAIL}❌ Application error: {str(e)}{Colors.ENDC}")
|
|
275
|
+
finally:
|
|
276
|
+
end_time = time.time()
|
|
277
|
+
print(
|
|
278
|
+
f"\n{Colors.BOLD}{Colors.CYAN}⏱️ Total runtime: {end_time - start_time:.2f} seconds{Colors.ENDC}"
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
# 清理缓存文件
|
|
282
|
+
print(f"{Colors.YELLOW}🧹 Cleaning up cache files...{Colors.ENDC}")
|
|
283
|
+
if os.name == "nt": # Windows
|
|
284
|
+
os.system(
|
|
285
|
+
"powershell -Command \"Get-ChildItem -Path . -Filter '__pycache__' -Recurse -Directory | Remove-Item -Recurse -Force\" 2>nul"
|
|
286
|
+
)
|
|
287
|
+
else: # Unix/Linux/macOS
|
|
288
|
+
os.system('find . -type d -name "__pycache__" -exec rm -r {} + 2>/dev/null')
|
|
289
|
+
|
|
290
|
+
print(
|
|
291
|
+
f"{Colors.OKGREEN}✨ Goodbye! Thanks for using DeepCode CLI! ✨{Colors.ENDC}"
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
if __name__ == "__main__":
|
|
296
|
+
asyncio.run(main())
|