jarvis-ai-assistant 0.7.16__py3-none-any.whl → 1.0.2__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 +567 -222
- jarvis/jarvis_agent/agent_manager.py +19 -12
- jarvis/jarvis_agent/builtin_input_handler.py +79 -11
- jarvis/jarvis_agent/config_editor.py +7 -2
- jarvis/jarvis_agent/event_bus.py +24 -13
- jarvis/jarvis_agent/events.py +19 -1
- jarvis/jarvis_agent/file_context_handler.py +67 -64
- jarvis/jarvis_agent/file_methodology_manager.py +38 -24
- jarvis/jarvis_agent/jarvis.py +186 -114
- jarvis/jarvis_agent/language_extractors/__init__.py +8 -1
- jarvis/jarvis_agent/language_extractors/c_extractor.py +7 -4
- jarvis/jarvis_agent/language_extractors/cpp_extractor.py +9 -4
- jarvis/jarvis_agent/language_extractors/go_extractor.py +7 -4
- jarvis/jarvis_agent/language_extractors/java_extractor.py +27 -20
- jarvis/jarvis_agent/language_extractors/javascript_extractor.py +22 -17
- jarvis/jarvis_agent/language_extractors/python_extractor.py +7 -4
- jarvis/jarvis_agent/language_extractors/rust_extractor.py +7 -4
- jarvis/jarvis_agent/language_extractors/typescript_extractor.py +22 -17
- jarvis/jarvis_agent/language_support_info.py +250 -219
- jarvis/jarvis_agent/main.py +19 -23
- jarvis/jarvis_agent/memory_manager.py +9 -6
- jarvis/jarvis_agent/methodology_share_manager.py +21 -15
- jarvis/jarvis_agent/output_handler.py +4 -2
- jarvis/jarvis_agent/prompt_builder.py +7 -6
- jarvis/jarvis_agent/prompt_manager.py +113 -8
- jarvis/jarvis_agent/prompts.py +317 -85
- jarvis/jarvis_agent/protocols.py +5 -2
- jarvis/jarvis_agent/run_loop.py +192 -32
- jarvis/jarvis_agent/session_manager.py +7 -3
- jarvis/jarvis_agent/share_manager.py +23 -13
- jarvis/jarvis_agent/shell_input_handler.py +12 -8
- jarvis/jarvis_agent/stdio_redirect.py +25 -26
- jarvis/jarvis_agent/task_analyzer.py +29 -23
- jarvis/jarvis_agent/task_list.py +869 -0
- jarvis/jarvis_agent/task_manager.py +26 -23
- jarvis/jarvis_agent/tool_executor.py +6 -5
- jarvis/jarvis_agent/tool_share_manager.py +24 -14
- jarvis/jarvis_agent/user_interaction.py +3 -3
- jarvis/jarvis_agent/utils.py +9 -1
- jarvis/jarvis_agent/web_bridge.py +37 -17
- jarvis/jarvis_agent/web_output_sink.py +5 -2
- jarvis/jarvis_agent/web_server.py +165 -36
- jarvis/jarvis_c2rust/__init__.py +1 -1
- jarvis/jarvis_c2rust/cli.py +260 -141
- jarvis/jarvis_c2rust/collector.py +37 -18
- jarvis/jarvis_c2rust/constants.py +60 -0
- jarvis/jarvis_c2rust/library_replacer.py +242 -1010
- jarvis/jarvis_c2rust/library_replacer_checkpoint.py +133 -0
- jarvis/jarvis_c2rust/library_replacer_llm.py +287 -0
- jarvis/jarvis_c2rust/library_replacer_loader.py +191 -0
- jarvis/jarvis_c2rust/library_replacer_output.py +134 -0
- jarvis/jarvis_c2rust/library_replacer_prompts.py +124 -0
- jarvis/jarvis_c2rust/library_replacer_utils.py +188 -0
- jarvis/jarvis_c2rust/llm_module_agent.py +98 -1044
- jarvis/jarvis_c2rust/llm_module_agent_apply.py +170 -0
- jarvis/jarvis_c2rust/llm_module_agent_executor.py +288 -0
- jarvis/jarvis_c2rust/llm_module_agent_loader.py +170 -0
- jarvis/jarvis_c2rust/llm_module_agent_prompts.py +268 -0
- jarvis/jarvis_c2rust/llm_module_agent_types.py +57 -0
- jarvis/jarvis_c2rust/llm_module_agent_utils.py +150 -0
- jarvis/jarvis_c2rust/llm_module_agent_validator.py +119 -0
- jarvis/jarvis_c2rust/loaders.py +28 -10
- jarvis/jarvis_c2rust/models.py +5 -2
- jarvis/jarvis_c2rust/optimizer.py +192 -1974
- jarvis/jarvis_c2rust/optimizer_build_fix.py +286 -0
- jarvis/jarvis_c2rust/optimizer_clippy.py +766 -0
- jarvis/jarvis_c2rust/optimizer_config.py +49 -0
- jarvis/jarvis_c2rust/optimizer_docs.py +183 -0
- jarvis/jarvis_c2rust/optimizer_options.py +48 -0
- jarvis/jarvis_c2rust/optimizer_progress.py +469 -0
- jarvis/jarvis_c2rust/optimizer_report.py +52 -0
- jarvis/jarvis_c2rust/optimizer_unsafe.py +309 -0
- jarvis/jarvis_c2rust/optimizer_utils.py +469 -0
- jarvis/jarvis_c2rust/optimizer_visibility.py +185 -0
- jarvis/jarvis_c2rust/scanner.py +229 -166
- jarvis/jarvis_c2rust/transpiler.py +531 -2732
- jarvis/jarvis_c2rust/transpiler_agents.py +503 -0
- jarvis/jarvis_c2rust/transpiler_build.py +1294 -0
- jarvis/jarvis_c2rust/transpiler_codegen.py +204 -0
- jarvis/jarvis_c2rust/transpiler_compile.py +146 -0
- jarvis/jarvis_c2rust/transpiler_config.py +178 -0
- jarvis/jarvis_c2rust/transpiler_context.py +122 -0
- jarvis/jarvis_c2rust/transpiler_executor.py +516 -0
- jarvis/jarvis_c2rust/transpiler_generation.py +278 -0
- jarvis/jarvis_c2rust/transpiler_git.py +163 -0
- jarvis/jarvis_c2rust/transpiler_mod_utils.py +225 -0
- jarvis/jarvis_c2rust/transpiler_modules.py +336 -0
- jarvis/jarvis_c2rust/transpiler_planning.py +394 -0
- jarvis/jarvis_c2rust/transpiler_review.py +1196 -0
- jarvis/jarvis_c2rust/transpiler_symbols.py +176 -0
- jarvis/jarvis_c2rust/utils.py +269 -79
- jarvis/jarvis_code_agent/after_change.py +233 -0
- jarvis/jarvis_code_agent/build_validation_config.py +37 -30
- jarvis/jarvis_code_agent/builtin_rules.py +68 -0
- jarvis/jarvis_code_agent/code_agent.py +976 -1517
- jarvis/jarvis_code_agent/code_agent_build.py +227 -0
- jarvis/jarvis_code_agent/code_agent_diff.py +246 -0
- jarvis/jarvis_code_agent/code_agent_git.py +525 -0
- jarvis/jarvis_code_agent/code_agent_impact.py +177 -0
- jarvis/jarvis_code_agent/code_agent_lint.py +283 -0
- jarvis/jarvis_code_agent/code_agent_llm.py +159 -0
- jarvis/jarvis_code_agent/code_agent_postprocess.py +105 -0
- jarvis/jarvis_code_agent/code_agent_prompts.py +46 -0
- jarvis/jarvis_code_agent/code_agent_rules.py +305 -0
- jarvis/jarvis_code_agent/code_analyzer/__init__.py +52 -48
- jarvis/jarvis_code_agent/code_analyzer/base_language.py +12 -10
- jarvis/jarvis_code_agent/code_analyzer/build_validator/__init__.py +12 -11
- jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +16 -12
- jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +26 -17
- jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +558 -104
- jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +27 -16
- jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +22 -18
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +21 -16
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +20 -16
- jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +27 -16
- jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +47 -23
- jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +71 -37
- jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +162 -35
- jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +111 -57
- jarvis/jarvis_code_agent/code_analyzer/build_validator.py +18 -12
- jarvis/jarvis_code_agent/code_analyzer/context_manager.py +185 -183
- jarvis/jarvis_code_agent/code_analyzer/context_recommender.py +2 -1
- jarvis/jarvis_code_agent/code_analyzer/dependency_analyzer.py +24 -15
- jarvis/jarvis_code_agent/code_analyzer/file_ignore.py +227 -141
- jarvis/jarvis_code_agent/code_analyzer/impact_analyzer.py +321 -247
- jarvis/jarvis_code_agent/code_analyzer/language_registry.py +37 -29
- jarvis/jarvis_code_agent/code_analyzer/language_support.py +21 -13
- jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +15 -9
- jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +75 -45
- jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +87 -52
- jarvis/jarvis_code_agent/code_analyzer/languages/java_language.py +84 -51
- jarvis/jarvis_code_agent/code_analyzer/languages/javascript_language.py +94 -64
- jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +109 -71
- jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +97 -63
- jarvis/jarvis_code_agent/code_analyzer/languages/typescript_language.py +103 -69
- jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +271 -268
- jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +76 -64
- jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +92 -19
- jarvis/jarvis_code_agent/diff_visualizer.py +998 -0
- jarvis/jarvis_code_agent/lint.py +223 -524
- jarvis/jarvis_code_agent/rule_share_manager.py +158 -0
- jarvis/jarvis_code_agent/rules/clean_code.md +144 -0
- jarvis/jarvis_code_agent/rules/code_review.md +115 -0
- jarvis/jarvis_code_agent/rules/documentation.md +165 -0
- jarvis/jarvis_code_agent/rules/generate_rules.md +52 -0
- jarvis/jarvis_code_agent/rules/performance.md +158 -0
- jarvis/jarvis_code_agent/rules/refactoring.md +139 -0
- jarvis/jarvis_code_agent/rules/security.md +160 -0
- jarvis/jarvis_code_agent/rules/tdd.md +78 -0
- jarvis/jarvis_code_agent/test_rules/cpp_test.md +118 -0
- jarvis/jarvis_code_agent/test_rules/go_test.md +98 -0
- jarvis/jarvis_code_agent/test_rules/java_test.md +99 -0
- jarvis/jarvis_code_agent/test_rules/javascript_test.md +113 -0
- jarvis/jarvis_code_agent/test_rules/php_test.md +117 -0
- jarvis/jarvis_code_agent/test_rules/python_test.md +91 -0
- jarvis/jarvis_code_agent/test_rules/ruby_test.md +102 -0
- jarvis/jarvis_code_agent/test_rules/rust_test.md +86 -0
- jarvis/jarvis_code_agent/utils.py +36 -26
- jarvis/jarvis_code_analysis/checklists/loader.py +21 -21
- jarvis/jarvis_code_analysis/code_review.py +64 -33
- jarvis/jarvis_data/config_schema.json +285 -192
- jarvis/jarvis_git_squash/main.py +8 -6
- jarvis/jarvis_git_utils/git_commiter.py +53 -76
- jarvis/jarvis_mcp/__init__.py +5 -2
- jarvis/jarvis_mcp/sse_mcp_client.py +40 -30
- jarvis/jarvis_mcp/stdio_mcp_client.py +27 -19
- jarvis/jarvis_mcp/streamable_mcp_client.py +35 -26
- jarvis/jarvis_memory_organizer/memory_organizer.py +78 -55
- jarvis/jarvis_methodology/main.py +48 -39
- jarvis/jarvis_multi_agent/__init__.py +56 -23
- jarvis/jarvis_multi_agent/main.py +15 -18
- jarvis/jarvis_platform/base.py +179 -111
- jarvis/jarvis_platform/human.py +27 -16
- jarvis/jarvis_platform/kimi.py +52 -45
- jarvis/jarvis_platform/openai.py +101 -40
- jarvis/jarvis_platform/registry.py +51 -33
- jarvis/jarvis_platform/tongyi.py +68 -38
- jarvis/jarvis_platform/yuanbao.py +59 -43
- jarvis/jarvis_platform_manager/main.py +68 -76
- jarvis/jarvis_platform_manager/service.py +24 -14
- jarvis/jarvis_rag/README_CONFIG.md +314 -0
- jarvis/jarvis_rag/README_DYNAMIC_LOADING.md +311 -0
- jarvis/jarvis_rag/README_ONLINE_MODELS.md +230 -0
- jarvis/jarvis_rag/__init__.py +57 -4
- jarvis/jarvis_rag/cache.py +3 -1
- jarvis/jarvis_rag/cli.py +48 -68
- jarvis/jarvis_rag/embedding_interface.py +39 -0
- jarvis/jarvis_rag/embedding_manager.py +7 -230
- jarvis/jarvis_rag/embeddings/__init__.py +41 -0
- jarvis/jarvis_rag/embeddings/base.py +114 -0
- jarvis/jarvis_rag/embeddings/cohere.py +66 -0
- jarvis/jarvis_rag/embeddings/edgefn.py +117 -0
- jarvis/jarvis_rag/embeddings/local.py +260 -0
- jarvis/jarvis_rag/embeddings/openai.py +62 -0
- jarvis/jarvis_rag/embeddings/registry.py +293 -0
- jarvis/jarvis_rag/llm_interface.py +8 -6
- jarvis/jarvis_rag/query_rewriter.py +8 -9
- jarvis/jarvis_rag/rag_pipeline.py +61 -52
- jarvis/jarvis_rag/reranker.py +7 -75
- jarvis/jarvis_rag/reranker_interface.py +32 -0
- jarvis/jarvis_rag/rerankers/__init__.py +41 -0
- jarvis/jarvis_rag/rerankers/base.py +109 -0
- jarvis/jarvis_rag/rerankers/cohere.py +67 -0
- jarvis/jarvis_rag/rerankers/edgefn.py +140 -0
- jarvis/jarvis_rag/rerankers/jina.py +79 -0
- jarvis/jarvis_rag/rerankers/local.py +89 -0
- jarvis/jarvis_rag/rerankers/registry.py +293 -0
- jarvis/jarvis_rag/retriever.py +58 -43
- jarvis/jarvis_sec/__init__.py +66 -141
- jarvis/jarvis_sec/agents.py +21 -17
- jarvis/jarvis_sec/analysis.py +80 -33
- jarvis/jarvis_sec/checkers/__init__.py +7 -13
- jarvis/jarvis_sec/checkers/c_checker.py +356 -164
- jarvis/jarvis_sec/checkers/rust_checker.py +47 -29
- jarvis/jarvis_sec/cli.py +43 -21
- jarvis/jarvis_sec/clustering.py +430 -272
- jarvis/jarvis_sec/file_manager.py +99 -55
- jarvis/jarvis_sec/parsers.py +9 -6
- jarvis/jarvis_sec/prompts.py +4 -3
- jarvis/jarvis_sec/report.py +44 -22
- jarvis/jarvis_sec/review.py +180 -107
- jarvis/jarvis_sec/status.py +50 -41
- jarvis/jarvis_sec/types.py +3 -0
- jarvis/jarvis_sec/utils.py +160 -83
- jarvis/jarvis_sec/verification.py +411 -181
- jarvis/jarvis_sec/workflow.py +132 -21
- jarvis/jarvis_smart_shell/main.py +28 -41
- jarvis/jarvis_stats/cli.py +14 -12
- jarvis/jarvis_stats/stats.py +28 -19
- jarvis/jarvis_stats/storage.py +14 -8
- jarvis/jarvis_stats/visualizer.py +12 -7
- jarvis/jarvis_tools/base.py +5 -2
- jarvis/jarvis_tools/clear_memory.py +13 -9
- jarvis/jarvis_tools/cli/main.py +23 -18
- jarvis/jarvis_tools/edit_file.py +572 -873
- jarvis/jarvis_tools/execute_script.py +10 -7
- jarvis/jarvis_tools/file_analyzer.py +7 -8
- jarvis/jarvis_tools/meta_agent.py +287 -0
- jarvis/jarvis_tools/methodology.py +5 -3
- jarvis/jarvis_tools/read_code.py +305 -1438
- jarvis/jarvis_tools/read_symbols.py +50 -17
- jarvis/jarvis_tools/read_webpage.py +19 -18
- jarvis/jarvis_tools/registry.py +435 -156
- jarvis/jarvis_tools/retrieve_memory.py +16 -11
- jarvis/jarvis_tools/save_memory.py +8 -6
- jarvis/jarvis_tools/search_web.py +31 -31
- jarvis/jarvis_tools/sub_agent.py +32 -28
- jarvis/jarvis_tools/sub_code_agent.py +44 -60
- jarvis/jarvis_tools/task_list_manager.py +1811 -0
- jarvis/jarvis_tools/virtual_tty.py +29 -19
- jarvis/jarvis_utils/__init__.py +4 -0
- jarvis/jarvis_utils/builtin_replace_map.py +2 -1
- jarvis/jarvis_utils/clipboard.py +9 -8
- jarvis/jarvis_utils/collections.py +331 -0
- jarvis/jarvis_utils/config.py +699 -194
- jarvis/jarvis_utils/dialogue_recorder.py +294 -0
- jarvis/jarvis_utils/embedding.py +6 -3
- jarvis/jarvis_utils/file_processors.py +7 -1
- jarvis/jarvis_utils/fzf.py +9 -3
- jarvis/jarvis_utils/git_utils.py +71 -42
- jarvis/jarvis_utils/globals.py +116 -32
- jarvis/jarvis_utils/http.py +6 -2
- jarvis/jarvis_utils/input.py +318 -83
- jarvis/jarvis_utils/jsonnet_compat.py +119 -104
- jarvis/jarvis_utils/methodology.py +37 -28
- jarvis/jarvis_utils/output.py +201 -44
- jarvis/jarvis_utils/utils.py +986 -628
- {jarvis_ai_assistant-0.7.16.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/METADATA +49 -33
- jarvis_ai_assistant-1.0.2.dist-info/RECORD +304 -0
- jarvis/jarvis_code_agent/code_analyzer/structured_code.py +0 -556
- jarvis/jarvis_tools/generate_new_tool.py +0 -205
- jarvis/jarvis_tools/lsp_client.py +0 -1552
- jarvis/jarvis_tools/rewrite_file.py +0 -105
- jarvis_ai_assistant-0.7.16.dist-info/RECORD +0 -218
- {jarvis_ai_assistant-0.7.16.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.7.16.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.7.16.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.7.16.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/top_level.txt +0 -0
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
import os
|
|
3
3
|
import tempfile
|
|
4
4
|
from pathlib import Path
|
|
5
|
-
from typing import Any
|
|
5
|
+
from typing import Any
|
|
6
|
+
from typing import Dict
|
|
7
|
+
from typing import List
|
|
6
8
|
|
|
9
|
+
from jarvis.jarvis_utils.output import PrettyOutput
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
class ScriptTool:
|
|
@@ -110,9 +113,11 @@ class ScriptTool:
|
|
|
110
113
|
)
|
|
111
114
|
|
|
112
115
|
# Execute command with optional timeout in non-interactive mode
|
|
113
|
-
from jarvis.jarvis_utils.config import get_script_execution_timeout, is_non_interactive
|
|
114
116
|
import subprocess
|
|
115
117
|
|
|
118
|
+
from jarvis.jarvis_utils.config import get_script_execution_timeout
|
|
119
|
+
from jarvis.jarvis_utils.config import is_non_interactive
|
|
120
|
+
|
|
116
121
|
timed_out = False
|
|
117
122
|
if is_non_interactive():
|
|
118
123
|
proc = None
|
|
@@ -149,7 +154,7 @@ class ScriptTool:
|
|
|
149
154
|
proc.wait()
|
|
150
155
|
except Exception:
|
|
151
156
|
pass
|
|
152
|
-
|
|
157
|
+
PrettyOutput.auto_print(f"❌ {str(e)}")
|
|
153
158
|
# Attempt to read any partial output if available
|
|
154
159
|
try:
|
|
155
160
|
output = self.get_display_output(output_file)
|
|
@@ -203,7 +208,7 @@ class ScriptTool:
|
|
|
203
208
|
Path(output_file).unlink(missing_ok=True)
|
|
204
209
|
|
|
205
210
|
except Exception as e:
|
|
206
|
-
|
|
211
|
+
PrettyOutput.auto_print(f"❌ {str(e)}")
|
|
207
212
|
return {"success": False, "stdout": "", "stderr": str(e)}
|
|
208
213
|
|
|
209
214
|
def execute(self, args: Dict) -> Dict[str, Any]:
|
|
@@ -231,7 +236,5 @@ class ScriptTool:
|
|
|
231
236
|
return self._execute_script_with_interpreter(interpreter, script_content)
|
|
232
237
|
|
|
233
238
|
except Exception as e:
|
|
234
|
-
|
|
239
|
+
PrettyOutput.auto_print(f"❌ {str(e)}")
|
|
235
240
|
return {"success": False, "stdout": "", "stderr": str(e)}
|
|
236
|
-
|
|
237
|
-
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import os
|
|
3
|
-
from typing import Any
|
|
4
|
-
|
|
3
|
+
from typing import Any
|
|
4
|
+
from typing import Dict
|
|
5
5
|
|
|
6
6
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
7
|
+
from jarvis.jarvis_utils.output import PrettyOutput
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
class FileAnalyzerTool:
|
|
@@ -51,10 +52,8 @@ class FileAnalyzerTool:
|
|
|
51
52
|
else:
|
|
52
53
|
missing_files.append(file_path)
|
|
53
54
|
if missing_files:
|
|
54
|
-
missing_list =
|
|
55
|
-
|
|
56
|
-
f"⚠️ 以下文件不存在:\n{missing_list}"
|
|
57
|
-
)
|
|
55
|
+
missing_list = "\n".join(f" - {p}" for p in missing_files)
|
|
56
|
+
PrettyOutput.auto_print(f"⚠️ 以下文件不存在:\n{missing_list}")
|
|
58
57
|
|
|
59
58
|
if not valid_files:
|
|
60
59
|
return {"success": False, "stdout": "", "stderr": "没有找到有效的文件"}
|
|
@@ -80,7 +79,7 @@ class FileAnalyzerTool:
|
|
|
80
79
|
try:
|
|
81
80
|
upload_result = platform.upload_files(valid_files)
|
|
82
81
|
if not upload_result:
|
|
83
|
-
|
|
82
|
+
PrettyOutput.auto_print("❌ 文件上传失败")
|
|
84
83
|
return {
|
|
85
84
|
"success": False,
|
|
86
85
|
"stdout": "",
|
|
@@ -88,7 +87,7 @@ class FileAnalyzerTool:
|
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
except Exception as e:
|
|
91
|
-
|
|
90
|
+
PrettyOutput.auto_print(f"❌ 文件上传失败: {str(e)}")
|
|
92
91
|
return {
|
|
93
92
|
"success": False,
|
|
94
93
|
"stdout": "",
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
from typing import Dict
|
|
6
|
+
|
|
7
|
+
from jarvis.jarvis_utils.config import get_data_dir
|
|
8
|
+
from jarvis.jarvis_utils.output import PrettyOutput
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class meta_agent:
|
|
12
|
+
"""元代理(Meta-Agent)工具:负责自举和进化 Jarvis 工具生态。
|
|
13
|
+
|
|
14
|
+
该工具本身利用 CodeAgent/Agent 分析需求、生成/改进其他工具代码,并自动完成注册与集成,
|
|
15
|
+
是一个可以“创造和改造工具的工具”,体现 Jarvis 的自举和自演化能力。
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
name = "meta_agent"
|
|
19
|
+
description = (
|
|
20
|
+
"元代理(Meta-Agent)工具:用于**根据自然语言需求自动创建或改进 Jarvis 工具**,并完成注册集成。"
|
|
21
|
+
"核心能力:1)调用 CodeAgent 生成完整可用的新工具代码(包含参数定义、错误处理、最佳实践模板);"
|
|
22
|
+
"2)在生成后自动写入到 data/tools 目录并注册到 ToolRegistry;"
|
|
23
|
+
"3)支持在新工具内部编排现有 Agent(通用任务编排、IIRIPER 工作流、task_list_manager)和 CodeAgent(代码修改、构建验证、lint、review 等);"
|
|
24
|
+
"4)支持通过再次调用 meta_agent 对已有工具进行自举式改进(自我分析和演化)。"
|
|
25
|
+
"调用方式:传入 tool_name(工具名/文件名)与 function_description(目标功能的清晰描述),返回值中包含生成状态和新工具文件的绝对路径。"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
parameters = {
|
|
29
|
+
"type": "object",
|
|
30
|
+
"properties": {
|
|
31
|
+
"tool_name": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"description": "要生成或改进的工具名称,将同时用作文件名(<name>.py)和工具类名",
|
|
34
|
+
},
|
|
35
|
+
"function_description": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "工具的目标功能与使用场景描述:应尽量具体,包含输入参数含义、预期输出、约束条件(例如只读/允许写文件)、是否需要编排 Agent/CodeAgent 等信息",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
"required": ["tool_name", "function_description"],
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def check() -> bool:
|
|
45
|
+
"""检查工具是否可用"""
|
|
46
|
+
# 检查数据目录是否存在
|
|
47
|
+
data_dir = get_data_dir()
|
|
48
|
+
tools_dir = Path(data_dir) / "tools"
|
|
49
|
+
|
|
50
|
+
# 如果tools目录不存在,尝试创建
|
|
51
|
+
if not tools_dir.exists():
|
|
52
|
+
try:
|
|
53
|
+
tools_dir.mkdir(parents=True, exist_ok=True)
|
|
54
|
+
return True
|
|
55
|
+
except Exception as e:
|
|
56
|
+
PrettyOutput.auto_print(f"❌ 无法创建工具目录 {tools_dir}: {e}")
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
return True
|
|
60
|
+
|
|
61
|
+
def _build_enhanced_prompt(
|
|
62
|
+
self, tool_name: str, function_description: str, jarvis_dir: Path
|
|
63
|
+
) -> str:
|
|
64
|
+
"""构建增强的提示词,包含关键参考文件"""
|
|
65
|
+
|
|
66
|
+
key_files = [
|
|
67
|
+
jarvis_dir / "jarvis_tools" / "registry.py",
|
|
68
|
+
jarvis_dir / "jarvis_tools" / "base.py",
|
|
69
|
+
jarvis_dir / "jarvis_agent" / "__init__.py",
|
|
70
|
+
jarvis_dir / "jarvis_code_agent" / "code_agent.py",
|
|
71
|
+
jarvis_dir / "jarvis_utils" / "config.py",
|
|
72
|
+
jarvis_dir / "jarvis_utils" / "output.py",
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
files_info = "\n".join([f"- {f.absolute()}" for f in key_files])
|
|
76
|
+
|
|
77
|
+
return f"""请根据用户需求生成一个新的Jarvis工具。
|
|
78
|
+
|
|
79
|
+
工具要求:
|
|
80
|
+
- 工具名称:{tool_name}
|
|
81
|
+
- 功能描述:{function_description}
|
|
82
|
+
- 生成的文件名:{tool_name}.py
|
|
83
|
+
- 文件保存路径:{jarvis_dir.parent.parent / "data" / "tools" / f"{tool_name}.py"}
|
|
84
|
+
- 必须继承自Tool基类(参考:src/jarvis/jarvis_tools/base.py)
|
|
85
|
+
- 必须实现name、description、parameters、execute方法
|
|
86
|
+
|
|
87
|
+
关键参考文件:
|
|
88
|
+
{files_info}
|
|
89
|
+
|
|
90
|
+
其他文件也可酌情参考。
|
|
91
|
+
|
|
92
|
+
### Agent / CodeAgent 关键用法(仅列核心要点,详细规则请阅读源码的绝对路径)
|
|
93
|
+
- Agent(通用 Agent):
|
|
94
|
+
- 职责:通用任务编排与对话式工作流,严格遵循 IIRIPER(INTENT → RESEARCH → INNOVATE → PLAN → EXECUTE → REVIEW)。
|
|
95
|
+
- 初始化要点:`Agent(system_prompt=..., name=..., model_group=..., use_tools=[...], non_interactive=...)`,大部分默认行为(记忆、方法论、工具过滤等)在 `{(jarvis_dir / "jarvis_agent" / "__init__.py").absolute()}` 中定义。
|
|
96
|
+
- 典型用法:通过 `agent.run(user_input)` 启动完整闭环,内部会自动处理系统提示、工具调用、task_list_manager 调度和总结;总结与返回值行为由 `summary_prompt` 和 `need_summary` 控制。
|
|
97
|
+
- 更多细节(参数含义、总结与返回值策略、事件回调等)请直接阅读:`{(jarvis_dir / "jarvis_agent" / "__init__.py").absolute()}`。
|
|
98
|
+
- CodeAgent(代码 Agent):
|
|
99
|
+
- 职责:代码分析与修改、git 操作、构建验证、lint、diff 展示和自动 review。
|
|
100
|
+
- 初始化要点:`CodeAgent(model_group=..., need_summary=..., non_interactive=True/False, append_tools=..., rule_names=...)`,工作流和提示词在 `{(jarvis_dir / "jarvis_code_agent" / "code_agent.py").absolute()}` 与 `{(jarvis_dir / "jarvis_code_agent" / "code_agent_prompts.py").absolute()}` 中定义。
|
|
101
|
+
- 典型用法:通过 `agent.run(requirement, prefix=..., suffix=...)` 驱动代码修改流程;内部会自动处理上下文分析、补丁生成、git 提交、构建校验、lint 与 review,`run` 的返回值通常是“结果摘要字符串或 None”。
|
|
102
|
+
- 更多细节(review 流程、任务总结、返回值语义等)请直接阅读:`{(jarvis_dir / "jarvis_code_agent" / "code_agent.py").absolute()}` 与 `{(jarvis_dir / "jarvis_code_agent" / "code_agent_prompts.py").absolute()}`。
|
|
103
|
+
|
|
104
|
+
在本工具生成的新工具中,推荐:
|
|
105
|
+
- 使用 Agent 负责上层的需求分析、IIRIPER 工作流以及多步骤任务编排;
|
|
106
|
+
- 使用 CodeAgent 负责具体代码层面的修改、重构和验证。
|
|
107
|
+
|
|
108
|
+
生成的工具必须具备以下特性:
|
|
109
|
+
1. 自举能力:能够调用现有package中的Agent和CodeAgent
|
|
110
|
+
2. 自我进化:能够利用现有的CodeAgent功能
|
|
111
|
+
3. 自动注册:生成后能够立即注册到工具系统
|
|
112
|
+
4. 完整功能:包含check()静态方法和execute()实例方法
|
|
113
|
+
|
|
114
|
+
**强烈推荐使用Agent/CodeAgent**:
|
|
115
|
+
- 在execute()方法中应该优先使用CodeAgent处理复杂的代码任务
|
|
116
|
+
- 可以使用Agent进行需求分析和任务分解
|
|
117
|
+
- 示例代码模式:
|
|
118
|
+
```python
|
|
119
|
+
from jarvis.jarvis_agent import Agent
|
|
120
|
+
from jarvis.jarvis_code_agent.code_agent import CodeAgent
|
|
121
|
+
|
|
122
|
+
# 使用CodeAgent处理代码相关任务
|
|
123
|
+
agent = CodeAgent()
|
|
124
|
+
agent.run("你的代码生成需求")
|
|
125
|
+
|
|
126
|
+
# 或者使用普通Agent处理分析任务
|
|
127
|
+
agent = Agent()
|
|
128
|
+
agent.run("你的分析需求")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
工具模板要求:
|
|
132
|
+
```python
|
|
133
|
+
class {tool_name}:
|
|
134
|
+
name = "{tool_name}"
|
|
135
|
+
description = "{function_description}"
|
|
136
|
+
|
|
137
|
+
parameters = {{
|
|
138
|
+
"type": "object",
|
|
139
|
+
"properties": {{
|
|
140
|
+
# 根据功能定义参数
|
|
141
|
+
}},
|
|
142
|
+
"required": ["required_param1", "required_param2"]
|
|
143
|
+
}}
|
|
144
|
+
|
|
145
|
+
@staticmethod
|
|
146
|
+
def check() -> bool:
|
|
147
|
+
# 检查工具是否可用
|
|
148
|
+
return True
|
|
149
|
+
|
|
150
|
+
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
151
|
+
# 实现工具功能
|
|
152
|
+
# 可以调用:
|
|
153
|
+
# - from jarvis.jarvis_agent import Agent
|
|
154
|
+
# - from jarvis.jarvis_code_agent.code_agent import CodeAgent
|
|
155
|
+
# - 其他jarvis模块
|
|
156
|
+
|
|
157
|
+
# 自举能力示例:使用 meta_agent 对自身进行改进
|
|
158
|
+
# from jarvis.jarvis_tools.meta_agent import meta_agent
|
|
159
|
+
#
|
|
160
|
+
# # 生成改进版本
|
|
161
|
+
# improver = meta_agent()
|
|
162
|
+
# result = improver.execute({{
|
|
163
|
+
# "tool_name": "{tool_name}_improved",
|
|
164
|
+
# "function_description": "改进版本的{tool_name},基于使用反馈优化"
|
|
165
|
+
# }})
|
|
166
|
+
|
|
167
|
+
# 使用CodeAgent进行自我分析和改进
|
|
168
|
+
# agent = CodeAgent()
|
|
169
|
+
# analysis = agent.run("分析当前工具的性能瓶颈并提出改进方案")
|
|
170
|
+
|
|
171
|
+
pass
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
请生成完整的、可直接使用的Python代码,生成完成后不用进行测试与验证。"""
|
|
175
|
+
|
|
176
|
+
def _register_new_tool(self, agent, tool_name: str, tool_file_path: str) -> bool:
|
|
177
|
+
"""注册新生成的工具"""
|
|
178
|
+
try:
|
|
179
|
+
tool_registry = agent.get_tool_registry()
|
|
180
|
+
result = tool_registry.register_tool_by_file(tool_file_path)
|
|
181
|
+
if not result:
|
|
182
|
+
# 注册失败,清理生成的文件
|
|
183
|
+
try:
|
|
184
|
+
from pathlib import Path
|
|
185
|
+
|
|
186
|
+
Path(tool_file_path).unlink(missing_ok=True)
|
|
187
|
+
PrettyOutput.auto_print(
|
|
188
|
+
f"ℹ️ 已清理注册失败的工具文件: {tool_file_path}"
|
|
189
|
+
)
|
|
190
|
+
except Exception as cleanup_error:
|
|
191
|
+
PrettyOutput.auto_print(f"⚠️ 清理文件失败: {cleanup_error}")
|
|
192
|
+
return bool(result)
|
|
193
|
+
except Exception as e:
|
|
194
|
+
PrettyOutput.auto_print(f"❌ 注册工具失败: {e}")
|
|
195
|
+
# 注册异常时也尝试清理文件
|
|
196
|
+
try:
|
|
197
|
+
from pathlib import Path
|
|
198
|
+
|
|
199
|
+
Path(tool_file_path).unlink(missing_ok=True)
|
|
200
|
+
PrettyOutput.auto_print(f"ℹ️ 已清理注册异常的工具文件: {tool_file_path}")
|
|
201
|
+
except Exception as cleanup_error:
|
|
202
|
+
PrettyOutput.auto_print(f"⚠️ 清理文件失败: {cleanup_error}")
|
|
203
|
+
return False
|
|
204
|
+
|
|
205
|
+
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
206
|
+
"""
|
|
207
|
+
生成新工具并注册到当前的工具注册表中
|
|
208
|
+
|
|
209
|
+
参数:
|
|
210
|
+
args: 包含工具名称和工具代码的字典
|
|
211
|
+
|
|
212
|
+
返回:
|
|
213
|
+
Dict: 包含生成结果的字典
|
|
214
|
+
"""
|
|
215
|
+
tool_file_path = None
|
|
216
|
+
curr_dir = os.getcwd()
|
|
217
|
+
try:
|
|
218
|
+
data_dir = get_data_dir()
|
|
219
|
+
tools_dir = Path(data_dir) / "tools"
|
|
220
|
+
tools_dir.mkdir(parents=True, exist_ok=True)
|
|
221
|
+
os.chdir(tools_dir)
|
|
222
|
+
|
|
223
|
+
# 从参数中获取工具信息
|
|
224
|
+
tool_name = args["tool_name"]
|
|
225
|
+
function_description = args["function_description"]
|
|
226
|
+
|
|
227
|
+
# 验证工具名称
|
|
228
|
+
if not tool_name.isidentifier():
|
|
229
|
+
return {
|
|
230
|
+
"success": False,
|
|
231
|
+
"stdout": "",
|
|
232
|
+
"stderr": f"工具名称 '{tool_name}' 不是有效的Python标识符",
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
jarvis_dir = Path(__file__).parent.parent.resolve()
|
|
236
|
+
|
|
237
|
+
# 构建增强的提示词,包含关键参考文件
|
|
238
|
+
enhanced_prompt = self._build_enhanced_prompt(
|
|
239
|
+
tool_name, function_description, jarvis_dir
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
# 使用CodeAgent生成工具代码
|
|
243
|
+
from jarvis.jarvis_code_agent.code_agent import CodeAgent
|
|
244
|
+
from jarvis.jarvis_utils.globals import get_global_model_group
|
|
245
|
+
|
|
246
|
+
# 使用全局模型组和标准配置创建CodeAgent
|
|
247
|
+
model_group = get_global_model_group()
|
|
248
|
+
agent = CodeAgent(
|
|
249
|
+
model_group=model_group,
|
|
250
|
+
need_summary=True,
|
|
251
|
+
non_interactive=True,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
try:
|
|
255
|
+
# 使用CodeAgent运行并生成工具代码
|
|
256
|
+
# CodeAgent会自动处理代码生成和文件写入
|
|
257
|
+
agent.auto_complete = True
|
|
258
|
+
agent.run(enhanced_prompt)
|
|
259
|
+
|
|
260
|
+
# 查找生成的工具文件
|
|
261
|
+
tool_file_path = tools_dir / f"{tool_name}.py"
|
|
262
|
+
if tool_file_path.exists():
|
|
263
|
+
# 自动注册新工具
|
|
264
|
+
self._register_new_tool(agent, tool_name, str(tool_file_path))
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
"success": True,
|
|
268
|
+
"stdout": f"成功生成并注册工具:{tool_name}\n文件路径:{tool_file_path}",
|
|
269
|
+
"stderr": "",
|
|
270
|
+
}
|
|
271
|
+
else:
|
|
272
|
+
return {
|
|
273
|
+
"success": False,
|
|
274
|
+
"stdout": "",
|
|
275
|
+
"stderr": "CodeAgent未能生成工具文件",
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
except Exception as e:
|
|
279
|
+
return {
|
|
280
|
+
"success": False,
|
|
281
|
+
"stdout": "",
|
|
282
|
+
"stderr": f"生成工具时出错:{str(e)}",
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
finally:
|
|
286
|
+
if curr_dir:
|
|
287
|
+
os.chdir(curr_dir)
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import hashlib
|
|
3
3
|
import json
|
|
4
4
|
import os
|
|
5
|
-
from typing import Any
|
|
5
|
+
from typing import Any
|
|
6
|
+
from typing import Dict
|
|
6
7
|
|
|
7
8
|
from jarvis.jarvis_utils.config import get_data_dir
|
|
9
|
+
from jarvis.jarvis_utils.output import PrettyOutput
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
class MethodologyTool:
|
|
@@ -44,7 +46,7 @@ class MethodologyTool:
|
|
|
44
46
|
try:
|
|
45
47
|
os.makedirs(self.methodology_dir, exist_ok=True)
|
|
46
48
|
except Exception as e:
|
|
47
|
-
|
|
49
|
+
PrettyOutput.auto_print(f"❌ 创建方法论目录失败:{str(e)}")
|
|
48
50
|
|
|
49
51
|
def _get_methodology_file_path(self, problem_type: str) -> str:
|
|
50
52
|
"""
|
|
@@ -126,7 +128,7 @@ class MethodologyTool:
|
|
|
126
128
|
indent=2,
|
|
127
129
|
)
|
|
128
130
|
|
|
129
|
-
|
|
131
|
+
PrettyOutput.auto_print(f"ℹ️ 方法论已保存到 {file_path}")
|
|
130
132
|
|
|
131
133
|
action = "更新" if os.path.exists(file_path) else "添加"
|
|
132
134
|
return {
|