jarvis-ai-assistant 0.3.30__py3-none-any.whl → 0.7.6__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.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +458 -152
- jarvis/jarvis_agent/agent_manager.py +17 -13
- jarvis/jarvis_agent/builtin_input_handler.py +2 -6
- jarvis/jarvis_agent/config_editor.py +2 -7
- jarvis/jarvis_agent/event_bus.py +82 -12
- jarvis/jarvis_agent/file_context_handler.py +329 -0
- jarvis/jarvis_agent/file_methodology_manager.py +3 -4
- jarvis/jarvis_agent/jarvis.py +628 -55
- jarvis/jarvis_agent/language_extractors/__init__.py +57 -0
- jarvis/jarvis_agent/language_extractors/c_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/cpp_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/go_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/java_extractor.py +84 -0
- jarvis/jarvis_agent/language_extractors/javascript_extractor.py +79 -0
- jarvis/jarvis_agent/language_extractors/python_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/rust_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/typescript_extractor.py +84 -0
- jarvis/jarvis_agent/language_support_info.py +486 -0
- jarvis/jarvis_agent/main.py +34 -10
- jarvis/jarvis_agent/memory_manager.py +7 -16
- jarvis/jarvis_agent/methodology_share_manager.py +10 -16
- jarvis/jarvis_agent/prompt_manager.py +1 -1
- jarvis/jarvis_agent/prompts.py +193 -171
- jarvis/jarvis_agent/protocols.py +8 -12
- jarvis/jarvis_agent/run_loop.py +105 -9
- jarvis/jarvis_agent/session_manager.py +2 -3
- jarvis/jarvis_agent/share_manager.py +20 -22
- jarvis/jarvis_agent/shell_input_handler.py +1 -2
- jarvis/jarvis_agent/stdio_redirect.py +295 -0
- jarvis/jarvis_agent/task_analyzer.py +31 -6
- jarvis/jarvis_agent/task_manager.py +11 -27
- jarvis/jarvis_agent/tool_executor.py +2 -3
- jarvis/jarvis_agent/tool_share_manager.py +12 -24
- jarvis/jarvis_agent/utils.py +5 -1
- jarvis/jarvis_agent/web_bridge.py +189 -0
- jarvis/jarvis_agent/web_output_sink.py +53 -0
- jarvis/jarvis_agent/web_server.py +786 -0
- jarvis/jarvis_c2rust/__init__.py +26 -0
- jarvis/jarvis_c2rust/cli.py +575 -0
- jarvis/jarvis_c2rust/collector.py +250 -0
- jarvis/jarvis_c2rust/constants.py +26 -0
- jarvis/jarvis_c2rust/library_replacer.py +1254 -0
- jarvis/jarvis_c2rust/llm_module_agent.py +1272 -0
- jarvis/jarvis_c2rust/loaders.py +207 -0
- jarvis/jarvis_c2rust/models.py +28 -0
- jarvis/jarvis_c2rust/optimizer.py +2157 -0
- jarvis/jarvis_c2rust/scanner.py +1681 -0
- jarvis/jarvis_c2rust/transpiler.py +2983 -0
- jarvis/jarvis_c2rust/utils.py +385 -0
- jarvis/jarvis_code_agent/build_validation_config.py +132 -0
- jarvis/jarvis_code_agent/code_agent.py +1371 -220
- jarvis/jarvis_code_agent/code_analyzer/__init__.py +65 -0
- jarvis/jarvis_code_agent/code_analyzer/base_language.py +74 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/__init__.py +44 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +106 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +74 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +125 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +72 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +70 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +53 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +47 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +61 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +110 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +154 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +110 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +153 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator.py +43 -0
- jarvis/jarvis_code_agent/code_analyzer/context_manager.py +648 -0
- jarvis/jarvis_code_agent/code_analyzer/context_recommender.py +18 -0
- jarvis/jarvis_code_agent/code_analyzer/dependency_analyzer.py +132 -0
- jarvis/jarvis_code_agent/code_analyzer/file_ignore.py +330 -0
- jarvis/jarvis_code_agent/code_analyzer/impact_analyzer.py +781 -0
- jarvis/jarvis_code_agent/code_analyzer/language_registry.py +185 -0
- jarvis/jarvis_code_agent/code_analyzer/language_support.py +110 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +49 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +299 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +215 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/java_language.py +212 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/javascript_language.py +254 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +269 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +281 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/typescript_language.py +280 -0
- jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +605 -0
- jarvis/jarvis_code_agent/code_analyzer/structured_code.py +556 -0
- jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +252 -0
- jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +58 -0
- jarvis/jarvis_code_agent/lint.py +501 -8
- jarvis/jarvis_code_agent/utils.py +141 -0
- jarvis/jarvis_code_analysis/code_review.py +493 -584
- jarvis/jarvis_data/config_schema.json +128 -12
- jarvis/jarvis_git_squash/main.py +4 -5
- jarvis/jarvis_git_utils/git_commiter.py +82 -75
- jarvis/jarvis_mcp/sse_mcp_client.py +22 -29
- jarvis/jarvis_mcp/stdio_mcp_client.py +12 -13
- jarvis/jarvis_mcp/streamable_mcp_client.py +15 -14
- jarvis/jarvis_memory_organizer/memory_organizer.py +55 -74
- jarvis/jarvis_methodology/main.py +32 -48
- jarvis/jarvis_multi_agent/__init__.py +287 -55
- jarvis/jarvis_multi_agent/main.py +36 -4
- jarvis/jarvis_platform/base.py +524 -202
- jarvis/jarvis_platform/human.py +7 -8
- jarvis/jarvis_platform/kimi.py +30 -36
- jarvis/jarvis_platform/openai.py +88 -25
- jarvis/jarvis_platform/registry.py +26 -10
- jarvis/jarvis_platform/tongyi.py +24 -25
- jarvis/jarvis_platform/yuanbao.py +32 -43
- jarvis/jarvis_platform_manager/main.py +66 -77
- jarvis/jarvis_platform_manager/service.py +8 -13
- jarvis/jarvis_rag/cli.py +53 -55
- jarvis/jarvis_rag/embedding_manager.py +13 -18
- jarvis/jarvis_rag/llm_interface.py +8 -9
- jarvis/jarvis_rag/query_rewriter.py +10 -21
- jarvis/jarvis_rag/rag_pipeline.py +24 -27
- jarvis/jarvis_rag/reranker.py +4 -5
- jarvis/jarvis_rag/retriever.py +28 -30
- jarvis/jarvis_sec/__init__.py +305 -0
- jarvis/jarvis_sec/agents.py +143 -0
- jarvis/jarvis_sec/analysis.py +276 -0
- jarvis/jarvis_sec/checkers/__init__.py +32 -0
- jarvis/jarvis_sec/checkers/c_checker.py +2680 -0
- jarvis/jarvis_sec/checkers/rust_checker.py +1108 -0
- jarvis/jarvis_sec/cli.py +139 -0
- jarvis/jarvis_sec/clustering.py +1439 -0
- jarvis/jarvis_sec/file_manager.py +427 -0
- jarvis/jarvis_sec/parsers.py +73 -0
- jarvis/jarvis_sec/prompts.py +268 -0
- jarvis/jarvis_sec/report.py +336 -0
- jarvis/jarvis_sec/review.py +453 -0
- jarvis/jarvis_sec/status.py +264 -0
- jarvis/jarvis_sec/types.py +20 -0
- jarvis/jarvis_sec/utils.py +499 -0
- jarvis/jarvis_sec/verification.py +848 -0
- jarvis/jarvis_sec/workflow.py +226 -0
- jarvis/jarvis_smart_shell/main.py +38 -87
- jarvis/jarvis_stats/cli.py +2 -2
- jarvis/jarvis_stats/stats.py +8 -8
- jarvis/jarvis_stats/storage.py +15 -21
- jarvis/jarvis_stats/visualizer.py +1 -1
- jarvis/jarvis_tools/clear_memory.py +3 -20
- jarvis/jarvis_tools/cli/main.py +21 -23
- jarvis/jarvis_tools/edit_file.py +1019 -132
- jarvis/jarvis_tools/execute_script.py +83 -25
- jarvis/jarvis_tools/file_analyzer.py +6 -9
- jarvis/jarvis_tools/generate_new_tool.py +14 -21
- jarvis/jarvis_tools/lsp_client.py +1552 -0
- jarvis/jarvis_tools/methodology.py +2 -3
- jarvis/jarvis_tools/read_code.py +1736 -35
- jarvis/jarvis_tools/read_symbols.py +140 -0
- jarvis/jarvis_tools/read_webpage.py +12 -13
- jarvis/jarvis_tools/registry.py +427 -200
- jarvis/jarvis_tools/retrieve_memory.py +20 -19
- jarvis/jarvis_tools/rewrite_file.py +72 -158
- jarvis/jarvis_tools/save_memory.py +3 -15
- jarvis/jarvis_tools/search_web.py +18 -18
- jarvis/jarvis_tools/sub_agent.py +36 -43
- jarvis/jarvis_tools/sub_code_agent.py +25 -26
- jarvis/jarvis_tools/virtual_tty.py +55 -33
- jarvis/jarvis_utils/clipboard.py +7 -10
- jarvis/jarvis_utils/config.py +232 -45
- jarvis/jarvis_utils/embedding.py +8 -5
- jarvis/jarvis_utils/fzf.py +8 -8
- jarvis/jarvis_utils/git_utils.py +225 -36
- jarvis/jarvis_utils/globals.py +3 -3
- jarvis/jarvis_utils/http.py +1 -1
- jarvis/jarvis_utils/input.py +99 -48
- jarvis/jarvis_utils/jsonnet_compat.py +465 -0
- jarvis/jarvis_utils/methodology.py +52 -48
- jarvis/jarvis_utils/utils.py +819 -491
- jarvis_ai_assistant-0.7.6.dist-info/METADATA +600 -0
- jarvis_ai_assistant-0.7.6.dist-info/RECORD +218 -0
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/entry_points.txt +4 -0
- jarvis/jarvis_agent/config.py +0 -92
- jarvis/jarvis_agent/edit_file_handler.py +0 -296
- jarvis/jarvis_platform/ai8.py +0 -332
- jarvis/jarvis_tools/ask_user.py +0 -54
- jarvis_ai_assistant-0.3.30.dist-info/METADATA +0 -381
- jarvis_ai_assistant-0.3.30.dist-info/RECORD +0 -137
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/top_level.txt +0 -0
|
@@ -4,7 +4,6 @@ import tempfile
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
from typing import Any, Dict, List
|
|
6
6
|
|
|
7
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
class ScriptTool:
|
|
@@ -14,18 +13,13 @@ class ScriptTool:
|
|
|
14
13
|
"""
|
|
15
14
|
|
|
16
15
|
name = "execute_script"
|
|
17
|
-
description =
|
|
18
|
-
"执行脚本并返回结果,支持任意解释器。"
|
|
19
|
-
+ "注意:由于模型上下文长度限制,请避免在脚本中输出大量信息,应该使用rg过滤输出。"
|
|
20
|
-
+ "与virtual_tty不同,此工具会创建一个临时的脚本文件,并使用脚本命令执行脚本,不具备交互式操作的能力,"
|
|
21
|
-
+ "适用于需要执行脚本并获取结果的场景。不适合需要交互式操作的场景(如:ssh连接、sftp传输、gdb/dlv调试等)。"
|
|
22
|
-
)
|
|
16
|
+
description = "执行脚本并返回结果,支持任意解释器。建议使用rg过滤大量输出。"
|
|
23
17
|
parameters = {
|
|
24
18
|
"type": "object",
|
|
25
19
|
"properties": {
|
|
26
20
|
"interpreter": {
|
|
27
21
|
"type": "string",
|
|
28
|
-
"description": "
|
|
22
|
+
"description": "脚本解释器(如bash、python3、perl等)。执行shell命令可使用bash。",
|
|
29
23
|
},
|
|
30
24
|
"script_content": {"type": "string", "description": "要执行的脚本内容"},
|
|
31
25
|
},
|
|
@@ -115,8 +109,72 @@ class ScriptTool:
|
|
|
115
109
|
f"script -q -c '{interpreter} {script_path}' {output_file}"
|
|
116
110
|
)
|
|
117
111
|
|
|
118
|
-
# Execute command
|
|
119
|
-
|
|
112
|
+
# Execute command with optional timeout in non-interactive mode
|
|
113
|
+
from jarvis.jarvis_utils.config import get_script_execution_timeout, is_non_interactive
|
|
114
|
+
import subprocess
|
|
115
|
+
|
|
116
|
+
timed_out = False
|
|
117
|
+
if is_non_interactive():
|
|
118
|
+
proc = None
|
|
119
|
+
try:
|
|
120
|
+
proc = subprocess.Popen(tee_command, shell=True)
|
|
121
|
+
try:
|
|
122
|
+
proc.wait(timeout=get_script_execution_timeout())
|
|
123
|
+
except subprocess.TimeoutExpired:
|
|
124
|
+
timed_out = True
|
|
125
|
+
try:
|
|
126
|
+
proc.terminate()
|
|
127
|
+
proc.wait(timeout=2)
|
|
128
|
+
except subprocess.TimeoutExpired:
|
|
129
|
+
try:
|
|
130
|
+
proc.kill()
|
|
131
|
+
proc.wait()
|
|
132
|
+
except Exception:
|
|
133
|
+
pass
|
|
134
|
+
except Exception:
|
|
135
|
+
try:
|
|
136
|
+
proc.kill()
|
|
137
|
+
proc.wait()
|
|
138
|
+
except Exception:
|
|
139
|
+
pass
|
|
140
|
+
except Exception as e:
|
|
141
|
+
# 确保进程被关闭
|
|
142
|
+
if proc is not None:
|
|
143
|
+
try:
|
|
144
|
+
proc.terminate()
|
|
145
|
+
proc.wait(timeout=1)
|
|
146
|
+
except Exception:
|
|
147
|
+
try:
|
|
148
|
+
proc.kill()
|
|
149
|
+
proc.wait()
|
|
150
|
+
except Exception:
|
|
151
|
+
pass
|
|
152
|
+
print(f"❌ {str(e)}")
|
|
153
|
+
# Attempt to read any partial output if available
|
|
154
|
+
try:
|
|
155
|
+
output = self.get_display_output(output_file)
|
|
156
|
+
except Exception as ee:
|
|
157
|
+
output = f"读取输出文件失败: {str(ee)}"
|
|
158
|
+
return {
|
|
159
|
+
"success": False,
|
|
160
|
+
"stdout": output,
|
|
161
|
+
"stderr": f"执行脚本失败: {str(e)}",
|
|
162
|
+
}
|
|
163
|
+
finally:
|
|
164
|
+
# 确保进程和文件描述符被关闭
|
|
165
|
+
if proc is not None:
|
|
166
|
+
try:
|
|
167
|
+
if proc.stdin:
|
|
168
|
+
proc.stdin.close()
|
|
169
|
+
if proc.stdout:
|
|
170
|
+
proc.stdout.close()
|
|
171
|
+
if proc.stderr:
|
|
172
|
+
proc.stderr.close()
|
|
173
|
+
except Exception:
|
|
174
|
+
pass
|
|
175
|
+
else:
|
|
176
|
+
# Execute command and capture return code
|
|
177
|
+
os.system(tee_command)
|
|
120
178
|
|
|
121
179
|
# Read and process output file
|
|
122
180
|
try:
|
|
@@ -125,12 +183,19 @@ class ScriptTool:
|
|
|
125
183
|
except Exception as e:
|
|
126
184
|
output = f"读取输出文件失败: {str(e)}"
|
|
127
185
|
|
|
128
|
-
# Return
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
186
|
+
# Return result (handle timeout in non-interactive mode)
|
|
187
|
+
if is_non_interactive() and timed_out:
|
|
188
|
+
return {
|
|
189
|
+
"success": False,
|
|
190
|
+
"stdout": output,
|
|
191
|
+
"stderr": f"执行超时(超过{get_script_execution_timeout()}秒),进程已被终止(非交互模式)。",
|
|
192
|
+
}
|
|
193
|
+
else:
|
|
194
|
+
return {
|
|
195
|
+
"success": True,
|
|
196
|
+
"stdout": output,
|
|
197
|
+
"stderr": "",
|
|
198
|
+
}
|
|
134
199
|
|
|
135
200
|
finally:
|
|
136
201
|
# Clean up temporary files
|
|
@@ -138,7 +203,7 @@ class ScriptTool:
|
|
|
138
203
|
Path(output_file).unlink(missing_ok=True)
|
|
139
204
|
|
|
140
205
|
except Exception as e:
|
|
141
|
-
|
|
206
|
+
print(f"❌ {str(e)}")
|
|
142
207
|
return {"success": False, "stdout": "", "stderr": str(e)}
|
|
143
208
|
|
|
144
209
|
def execute(self, args: Dict) -> Dict[str, Any]:
|
|
@@ -166,14 +231,7 @@ class ScriptTool:
|
|
|
166
231
|
return self._execute_script_with_interpreter(interpreter, script_content)
|
|
167
232
|
|
|
168
233
|
except Exception as e:
|
|
169
|
-
|
|
234
|
+
print(f"❌ {str(e)}")
|
|
170
235
|
return {"success": False, "stdout": "", "stderr": str(e)}
|
|
171
236
|
|
|
172
237
|
|
|
173
|
-
if __name__ == "__main__":
|
|
174
|
-
script_tool = ScriptTool()
|
|
175
|
-
PrettyOutput.print(
|
|
176
|
-
script_tool.get_display_output("/home/wangmaobin/code/Jarvis/a.txt"),
|
|
177
|
-
OutputType.CODE,
|
|
178
|
-
lang="text",
|
|
179
|
-
)
|
|
@@ -4,14 +4,11 @@ from typing import Any, Dict
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
7
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
8
7
|
|
|
9
8
|
|
|
10
9
|
class FileAnalyzerTool:
|
|
11
10
|
name = "file_analyzer"
|
|
12
|
-
description =
|
|
13
|
-
"""分析文件内容并提取关键信息。支持的文件:文本文件、word文档、pdf文件、图片"""
|
|
14
|
-
)
|
|
11
|
+
description = "分析文件内容并提取关键信息。支持文本、word、pdf、图片等格式。"
|
|
15
12
|
parameters = {
|
|
16
13
|
"type": "object",
|
|
17
14
|
"properties": {
|
|
@@ -54,9 +51,9 @@ class FileAnalyzerTool:
|
|
|
54
51
|
else:
|
|
55
52
|
missing_files.append(file_path)
|
|
56
53
|
if missing_files:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
missing_list = '\n'.join(f' - {p}' for p in missing_files)
|
|
55
|
+
print(
|
|
56
|
+
f"⚠️ 以下文件不存在:\n{missing_list}"
|
|
60
57
|
)
|
|
61
58
|
|
|
62
59
|
if not valid_files:
|
|
@@ -83,7 +80,7 @@ class FileAnalyzerTool:
|
|
|
83
80
|
try:
|
|
84
81
|
upload_result = platform.upload_files(valid_files)
|
|
85
82
|
if not upload_result:
|
|
86
|
-
|
|
83
|
+
print("❌ 文件上传失败")
|
|
87
84
|
return {
|
|
88
85
|
"success": False,
|
|
89
86
|
"stdout": "",
|
|
@@ -91,7 +88,7 @@ class FileAnalyzerTool:
|
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
except Exception as e:
|
|
94
|
-
|
|
91
|
+
print(f"❌ 文件上传失败: {str(e)}")
|
|
95
92
|
return {
|
|
96
93
|
"success": False,
|
|
97
94
|
"stdout": "",
|
|
@@ -3,19 +3,11 @@ from pathlib import Path
|
|
|
3
3
|
from typing import Any, Dict
|
|
4
4
|
|
|
5
5
|
from jarvis.jarvis_utils.config import get_data_dir
|
|
6
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
class generate_new_tool:
|
|
10
9
|
name = "generate_new_tool"
|
|
11
|
-
description = ""
|
|
12
|
-
生成并注册新的Jarvis工具。该工具会在用户数据目录下创建新的工具文件,
|
|
13
|
-
并自动注册到当前的工具注册表中。适用场景:1. 需要创建新的自定义工具;
|
|
14
|
-
2. 扩展Jarvis功能;3. 自动化重复性操作;4. 封装特定领域的功能。
|
|
15
|
-
重要提示:
|
|
16
|
-
1. `tool_name` 参数必须与 `tool_code` 中定义的 `name` 属性完全一致。
|
|
17
|
-
2. 在编写工具代码时,应尽量将工具执行的过程和结果打印出来,方便追踪工具的执行状态。
|
|
18
|
-
"""
|
|
10
|
+
description = "生成并注册新的Jarvis工具。在用户数据目录下创建工具文件并自动注册。注意:tool_name必须与tool_code中的name属性完全一致。"
|
|
19
11
|
|
|
20
12
|
parameters = {
|
|
21
13
|
"type": "object",
|
|
@@ -45,8 +37,8 @@ class generate_new_tool:
|
|
|
45
37
|
tools_dir.mkdir(parents=True, exist_ok=True)
|
|
46
38
|
return True
|
|
47
39
|
except Exception as e:
|
|
48
|
-
|
|
49
|
-
f"无法创建工具目录 {tools_dir}: {e}"
|
|
40
|
+
print(
|
|
41
|
+
f"❌ 无法创建工具目录 {tools_dir}: {e}"
|
|
50
42
|
)
|
|
51
43
|
return False
|
|
52
44
|
|
|
@@ -129,9 +121,8 @@ class generate_new_tool:
|
|
|
129
121
|
success_message += "\n已成功注册到当前会话的工具注册表中"
|
|
130
122
|
else:
|
|
131
123
|
# 注册失败,删除已创建的文件
|
|
132
|
-
|
|
133
|
-
f"注册工具 '{tool_name}' 失败,正在删除文件..."
|
|
134
|
-
OutputType.WARNING,
|
|
124
|
+
print(
|
|
125
|
+
f"⚠️ 注册工具 '{tool_name}' 失败,正在删除文件..."
|
|
135
126
|
)
|
|
136
127
|
if tool_file_path.exists():
|
|
137
128
|
tool_file_path.unlink()
|
|
@@ -141,8 +132,8 @@ class generate_new_tool:
|
|
|
141
132
|
"stderr": "工具文件已生成,但注册失败。文件已被删除。",
|
|
142
133
|
}
|
|
143
134
|
else:
|
|
144
|
-
|
|
145
|
-
"未找到工具注册表,无法自动注册工具"
|
|
135
|
+
print(
|
|
136
|
+
"⚠️ 未找到工具注册表,无法自动注册工具"
|
|
146
137
|
)
|
|
147
138
|
success_message += "\n注册到当前会话失败,可能需要重新启动Jarvis"
|
|
148
139
|
|
|
@@ -173,7 +164,9 @@ class generate_new_tool:
|
|
|
173
164
|
__import__(pkg)
|
|
174
165
|
except ImportError:
|
|
175
166
|
|
|
176
|
-
import subprocess
|
|
167
|
+
import subprocess
|
|
168
|
+
import sys
|
|
169
|
+
import os
|
|
177
170
|
from shutil import which as _which
|
|
178
171
|
# 优先使用 uv 安装(先查 venv 内 uv,再查 PATH 中 uv),否则回退到 python -m pip
|
|
179
172
|
if sys.platform == "win32":
|
|
@@ -189,14 +182,14 @@ class generate_new_tool:
|
|
|
189
182
|
|
|
190
183
|
|
|
191
184
|
except Exception as e:
|
|
192
|
-
|
|
185
|
+
print(f"⚠️ 依赖检查/安装失败: {str(e)}")
|
|
193
186
|
|
|
194
187
|
return {"success": True, "stdout": success_message, "stderr": ""}
|
|
195
188
|
|
|
196
189
|
except Exception as e:
|
|
197
190
|
# 如果发生异常,删除已创建的文件并返回失败响应
|
|
198
191
|
error_msg = f"生成工具失败: {str(e)}"
|
|
199
|
-
|
|
192
|
+
print(f"❌ {error_msg}")
|
|
200
193
|
|
|
201
194
|
# 删除已创建的文件
|
|
202
195
|
if tool_file_path and tool_file_path.exists():
|
|
@@ -205,8 +198,8 @@ class generate_new_tool:
|
|
|
205
198
|
tool_file_path.unlink()
|
|
206
199
|
|
|
207
200
|
except Exception as delete_error:
|
|
208
|
-
|
|
209
|
-
f"删除文件失败: {str(delete_error)}"
|
|
201
|
+
print(
|
|
202
|
+
f"❌ 删除文件失败: {str(delete_error)}"
|
|
210
203
|
)
|
|
211
204
|
|
|
212
205
|
return {"success": False, "stdout": "", "stderr": error_msg}
|