jarvis-ai-assistant 0.1.222__py3-none-any.whl → 0.7.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.
Files changed (162) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +1143 -245
  3. jarvis/jarvis_agent/agent_manager.py +97 -0
  4. jarvis/jarvis_agent/builtin_input_handler.py +12 -10
  5. jarvis/jarvis_agent/config_editor.py +57 -0
  6. jarvis/jarvis_agent/edit_file_handler.py +392 -99
  7. jarvis/jarvis_agent/event_bus.py +48 -0
  8. jarvis/jarvis_agent/events.py +157 -0
  9. jarvis/jarvis_agent/file_context_handler.py +79 -0
  10. jarvis/jarvis_agent/file_methodology_manager.py +117 -0
  11. jarvis/jarvis_agent/jarvis.py +1117 -147
  12. jarvis/jarvis_agent/main.py +78 -34
  13. jarvis/jarvis_agent/memory_manager.py +195 -0
  14. jarvis/jarvis_agent/methodology_share_manager.py +174 -0
  15. jarvis/jarvis_agent/prompt_manager.py +82 -0
  16. jarvis/jarvis_agent/prompts.py +46 -9
  17. jarvis/jarvis_agent/protocols.py +4 -1
  18. jarvis/jarvis_agent/rewrite_file_handler.py +141 -0
  19. jarvis/jarvis_agent/run_loop.py +146 -0
  20. jarvis/jarvis_agent/session_manager.py +9 -9
  21. jarvis/jarvis_agent/share_manager.py +228 -0
  22. jarvis/jarvis_agent/shell_input_handler.py +23 -3
  23. jarvis/jarvis_agent/stdio_redirect.py +295 -0
  24. jarvis/jarvis_agent/task_analyzer.py +212 -0
  25. jarvis/jarvis_agent/task_manager.py +154 -0
  26. jarvis/jarvis_agent/task_planner.py +496 -0
  27. jarvis/jarvis_agent/tool_executor.py +8 -4
  28. jarvis/jarvis_agent/tool_share_manager.py +139 -0
  29. jarvis/jarvis_agent/user_interaction.py +42 -0
  30. jarvis/jarvis_agent/utils.py +54 -0
  31. jarvis/jarvis_agent/web_bridge.py +189 -0
  32. jarvis/jarvis_agent/web_output_sink.py +53 -0
  33. jarvis/jarvis_agent/web_server.py +751 -0
  34. jarvis/jarvis_c2rust/__init__.py +26 -0
  35. jarvis/jarvis_c2rust/cli.py +613 -0
  36. jarvis/jarvis_c2rust/collector.py +258 -0
  37. jarvis/jarvis_c2rust/library_replacer.py +1122 -0
  38. jarvis/jarvis_c2rust/llm_module_agent.py +1300 -0
  39. jarvis/jarvis_c2rust/optimizer.py +960 -0
  40. jarvis/jarvis_c2rust/scanner.py +1681 -0
  41. jarvis/jarvis_c2rust/transpiler.py +2325 -0
  42. jarvis/jarvis_code_agent/build_validation_config.py +133 -0
  43. jarvis/jarvis_code_agent/code_agent.py +1605 -178
  44. jarvis/jarvis_code_agent/code_analyzer/__init__.py +62 -0
  45. jarvis/jarvis_code_agent/code_analyzer/base_language.py +74 -0
  46. jarvis/jarvis_code_agent/code_analyzer/build_validator/__init__.py +44 -0
  47. jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +102 -0
  48. jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +59 -0
  49. jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +125 -0
  50. jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +69 -0
  51. jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +38 -0
  52. jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +44 -0
  53. jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +38 -0
  54. jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +50 -0
  55. jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +93 -0
  56. jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +129 -0
  57. jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +54 -0
  58. jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +154 -0
  59. jarvis/jarvis_code_agent/code_analyzer/build_validator.py +43 -0
  60. jarvis/jarvis_code_agent/code_analyzer/context_manager.py +363 -0
  61. jarvis/jarvis_code_agent/code_analyzer/context_recommender.py +18 -0
  62. jarvis/jarvis_code_agent/code_analyzer/dependency_analyzer.py +132 -0
  63. jarvis/jarvis_code_agent/code_analyzer/file_ignore.py +330 -0
  64. jarvis/jarvis_code_agent/code_analyzer/impact_analyzer.py +781 -0
  65. jarvis/jarvis_code_agent/code_analyzer/language_registry.py +185 -0
  66. jarvis/jarvis_code_agent/code_analyzer/language_support.py +89 -0
  67. jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +31 -0
  68. jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +231 -0
  69. jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +183 -0
  70. jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +219 -0
  71. jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +209 -0
  72. jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +451 -0
  73. jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +77 -0
  74. jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +48 -0
  75. jarvis/jarvis_code_agent/lint.py +275 -13
  76. jarvis/jarvis_code_agent/utils.py +142 -0
  77. jarvis/jarvis_code_analysis/checklists/loader.py +20 -6
  78. jarvis/jarvis_code_analysis/code_review.py +583 -548
  79. jarvis/jarvis_data/config_schema.json +339 -28
  80. jarvis/jarvis_git_squash/main.py +22 -13
  81. jarvis/jarvis_git_utils/git_commiter.py +171 -55
  82. jarvis/jarvis_mcp/sse_mcp_client.py +22 -15
  83. jarvis/jarvis_mcp/stdio_mcp_client.py +4 -4
  84. jarvis/jarvis_mcp/streamable_mcp_client.py +36 -16
  85. jarvis/jarvis_memory_organizer/memory_organizer.py +753 -0
  86. jarvis/jarvis_methodology/main.py +48 -63
  87. jarvis/jarvis_multi_agent/__init__.py +302 -43
  88. jarvis/jarvis_multi_agent/main.py +70 -24
  89. jarvis/jarvis_platform/ai8.py +40 -23
  90. jarvis/jarvis_platform/base.py +210 -49
  91. jarvis/jarvis_platform/human.py +11 -1
  92. jarvis/jarvis_platform/kimi.py +82 -76
  93. jarvis/jarvis_platform/openai.py +73 -1
  94. jarvis/jarvis_platform/registry.py +8 -15
  95. jarvis/jarvis_platform/tongyi.py +115 -101
  96. jarvis/jarvis_platform/yuanbao.py +89 -63
  97. jarvis/jarvis_platform_manager/main.py +194 -132
  98. jarvis/jarvis_platform_manager/service.py +122 -86
  99. jarvis/jarvis_rag/cli.py +156 -53
  100. jarvis/jarvis_rag/embedding_manager.py +155 -12
  101. jarvis/jarvis_rag/llm_interface.py +10 -13
  102. jarvis/jarvis_rag/query_rewriter.py +63 -12
  103. jarvis/jarvis_rag/rag_pipeline.py +222 -40
  104. jarvis/jarvis_rag/reranker.py +26 -3
  105. jarvis/jarvis_rag/retriever.py +270 -14
  106. jarvis/jarvis_sec/__init__.py +3605 -0
  107. jarvis/jarvis_sec/checkers/__init__.py +32 -0
  108. jarvis/jarvis_sec/checkers/c_checker.py +2680 -0
  109. jarvis/jarvis_sec/checkers/rust_checker.py +1108 -0
  110. jarvis/jarvis_sec/cli.py +116 -0
  111. jarvis/jarvis_sec/report.py +257 -0
  112. jarvis/jarvis_sec/status.py +264 -0
  113. jarvis/jarvis_sec/types.py +20 -0
  114. jarvis/jarvis_sec/workflow.py +219 -0
  115. jarvis/jarvis_smart_shell/main.py +405 -137
  116. jarvis/jarvis_stats/__init__.py +13 -0
  117. jarvis/jarvis_stats/cli.py +387 -0
  118. jarvis/jarvis_stats/stats.py +711 -0
  119. jarvis/jarvis_stats/storage.py +612 -0
  120. jarvis/jarvis_stats/visualizer.py +282 -0
  121. jarvis/jarvis_tools/ask_user.py +1 -0
  122. jarvis/jarvis_tools/base.py +18 -2
  123. jarvis/jarvis_tools/clear_memory.py +239 -0
  124. jarvis/jarvis_tools/cli/main.py +220 -144
  125. jarvis/jarvis_tools/execute_script.py +52 -12
  126. jarvis/jarvis_tools/file_analyzer.py +17 -12
  127. jarvis/jarvis_tools/generate_new_tool.py +46 -24
  128. jarvis/jarvis_tools/read_code.py +277 -18
  129. jarvis/jarvis_tools/read_symbols.py +141 -0
  130. jarvis/jarvis_tools/read_webpage.py +86 -13
  131. jarvis/jarvis_tools/registry.py +294 -90
  132. jarvis/jarvis_tools/retrieve_memory.py +227 -0
  133. jarvis/jarvis_tools/save_memory.py +194 -0
  134. jarvis/jarvis_tools/search_web.py +62 -28
  135. jarvis/jarvis_tools/sub_agent.py +205 -0
  136. jarvis/jarvis_tools/sub_code_agent.py +217 -0
  137. jarvis/jarvis_tools/virtual_tty.py +330 -62
  138. jarvis/jarvis_utils/builtin_replace_map.py +4 -5
  139. jarvis/jarvis_utils/clipboard.py +90 -0
  140. jarvis/jarvis_utils/config.py +607 -50
  141. jarvis/jarvis_utils/embedding.py +3 -0
  142. jarvis/jarvis_utils/fzf.py +57 -0
  143. jarvis/jarvis_utils/git_utils.py +251 -29
  144. jarvis/jarvis_utils/globals.py +174 -17
  145. jarvis/jarvis_utils/http.py +58 -79
  146. jarvis/jarvis_utils/input.py +899 -153
  147. jarvis/jarvis_utils/methodology.py +210 -83
  148. jarvis/jarvis_utils/output.py +220 -137
  149. jarvis/jarvis_utils/utils.py +1906 -135
  150. jarvis_ai_assistant-0.7.0.dist-info/METADATA +465 -0
  151. jarvis_ai_assistant-0.7.0.dist-info/RECORD +192 -0
  152. {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/entry_points.txt +8 -2
  153. jarvis/jarvis_git_details/main.py +0 -265
  154. jarvis/jarvis_platform/oyi.py +0 -357
  155. jarvis/jarvis_tools/edit_file.py +0 -255
  156. jarvis/jarvis_tools/rewrite_file.py +0 -195
  157. jarvis_ai_assistant-0.1.222.dist-info/METADATA +0 -767
  158. jarvis_ai_assistant-0.1.222.dist-info/RECORD +0 -110
  159. /jarvis/{jarvis_git_details → jarvis_memory_organizer}/__init__.py +0 -0
  160. {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/WHEEL +0 -0
  161. {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/licenses/LICENSE +0 -0
  162. {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Makefile构建验证器模块
6
+
7
+ 提供Makefile项目的构建验证功能。
8
+ """
9
+
10
+ import os
11
+ import time
12
+ from typing import List, Optional
13
+
14
+ from .base import BuildValidatorBase, BuildResult, BuildSystem
15
+
16
+
17
+ class MakefileBuildValidator(BuildValidatorBase):
18
+ """Makefile构建验证器"""
19
+
20
+ def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
21
+ start_time = time.time()
22
+
23
+ # 尝试运行 make(如果存在Makefile)
24
+ makefile = os.path.join(self.project_root, "Makefile")
25
+ if not os.path.exists(makefile):
26
+ duration = time.time() - start_time
27
+ return BuildResult(
28
+ success=False,
29
+ output="Makefile不存在",
30
+ error_message="Makefile不存在",
31
+ build_system=BuildSystem.C_MAKEFILE,
32
+ duration=duration,
33
+ )
34
+
35
+ # 尝试 make -n(dry-run)来验证语法
36
+ returncode, stdout, stderr = self._run_command(
37
+ ["make", "-n"],
38
+ timeout=10,
39
+ )
40
+ duration = time.time() - start_time
41
+
42
+ success = returncode == 0
43
+ return BuildResult(
44
+ success=success,
45
+ output=stdout + stderr,
46
+ error_message=None if success else "Makefile语法检查失败",
47
+ build_system=BuildSystem.C_MAKEFILE,
48
+ duration=duration,
49
+ )
50
+
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Node.js构建验证器模块
6
+
7
+ 提供Node.js项目的构建验证功能。
8
+ """
9
+
10
+ import json
11
+ import os
12
+ import time
13
+ from typing import List, Optional
14
+
15
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
16
+ from .base import BuildValidatorBase, BuildResult, BuildSystem
17
+
18
+
19
+ class NodeJSBuildValidator(BuildValidatorBase):
20
+ """Node.js构建验证器"""
21
+
22
+ def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
23
+ start_time = time.time()
24
+
25
+ # 策略1: 尝试使用 tsc --noEmit(如果存在TypeScript)
26
+ tsconfig = os.path.join(self.project_root, "tsconfig.json")
27
+ if os.path.exists(tsconfig):
28
+ returncode, stdout, stderr = self._run_command(
29
+ ["npx", "tsc", "--noEmit"],
30
+ timeout=20,
31
+ )
32
+ duration = time.time() - start_time
33
+ success = returncode == 0
34
+ return BuildResult(
35
+ success=success,
36
+ output=stdout + stderr,
37
+ error_message=None if success else "TypeScript类型检查失败",
38
+ build_system=BuildSystem.NODEJS,
39
+ duration=duration,
40
+ )
41
+
42
+ # 策略2: 尝试运行 npm run build(如果存在build脚本)
43
+ package_json = os.path.join(self.project_root, "package.json")
44
+ if os.path.exists(package_json):
45
+ try:
46
+ with open(package_json, "r", encoding="utf-8") as f:
47
+ package_data = json.load(f)
48
+ scripts = package_data.get("scripts", {})
49
+ if "build" in scripts:
50
+ returncode, stdout, stderr = self._run_command(
51
+ ["npm", "run", "build"],
52
+ timeout=30,
53
+ )
54
+ duration = time.time() - start_time
55
+ success = returncode == 0
56
+ return BuildResult(
57
+ success=success,
58
+ output=stdout + stderr,
59
+ error_message=None if success else "npm build失败",
60
+ build_system=BuildSystem.NODEJS,
61
+ duration=duration,
62
+ )
63
+ except Exception as e:
64
+ PrettyOutput.print(f"读取package.json失败: {e}", OutputType.WARNING)
65
+
66
+ # 策略3: 使用 eslint 进行语法检查(如果存在)
67
+ if modified_files:
68
+ js_files = [f for f in modified_files if f.endswith((".js", ".jsx", ".ts", ".tsx"))]
69
+ if js_files:
70
+ # 尝试使用 eslint
71
+ returncode, stdout, stderr = self._run_command(
72
+ ["npx", "eslint", "--max-warnings=0"] + js_files[:5], # 限制文件数量
73
+ timeout=15,
74
+ )
75
+ duration = time.time() - start_time
76
+ # eslint返回非0可能是警告,不算失败
77
+ return BuildResult(
78
+ success=True, # 仅检查语法,警告不算失败
79
+ output=stdout + stderr,
80
+ error_message=None,
81
+ build_system=BuildSystem.NODEJS,
82
+ duration=duration,
83
+ )
84
+
85
+ duration = time.time() - start_time
86
+ return BuildResult(
87
+ success=True,
88
+ output="Node.js项目验证通过(无构建脚本)",
89
+ error_message=None,
90
+ build_system=BuildSystem.NODEJS,
91
+ duration=duration,
92
+ )
93
+
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Python构建验证器模块
6
+
7
+ 提供Python项目的构建验证功能。
8
+ """
9
+
10
+ import os
11
+ import time
12
+ from typing import List, Optional
13
+
14
+ from .base import BuildValidatorBase, BuildResult, BuildSystem
15
+
16
+
17
+ class PythonBuildValidator(BuildValidatorBase):
18
+ """Python构建验证器"""
19
+
20
+ def _extract_python_errors(self, output: str) -> str:
21
+ """提取Python错误信息"""
22
+ if not output:
23
+ return ""
24
+
25
+ lines = output.split("\n")
26
+ errors = []
27
+ in_error = False
28
+
29
+ for line in lines:
30
+ line_lower = line.lower()
31
+ # 检测错误关键词
32
+ if any(keyword in line_lower for keyword in ["error", "failed", "exception", "traceback", "syntaxerror", "indentationerror"]):
33
+ in_error = True
34
+ errors.append(line.strip())
35
+ elif in_error and line.strip():
36
+ # 继续收集错误相关的行
37
+ if line.strip().startswith(("File", " File", " ", "E ", "FAILED")):
38
+ errors.append(line.strip())
39
+ elif not line.strip().startswith("="):
40
+ # 如果遇到非错误相关的行,停止收集
41
+ if len(errors) > 0 and not any(keyword in line_lower for keyword in ["error", "failed", "exception"]):
42
+ break
43
+
44
+ # 如果收集到错误,返回前20行(限制长度)
45
+ if errors:
46
+ error_text = "\n".join(errors[:20])
47
+ # 如果太长,截断
48
+ if len(error_text) > 1000:
49
+ error_text = error_text[:1000] + "\n... (错误信息已截断)"
50
+ return error_text
51
+
52
+ # 如果没有提取到结构化错误,返回原始输出的前500字符
53
+ return output[:500] if output else ""
54
+
55
+ def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
56
+ start_time = time.time()
57
+
58
+ # 策略1: 尝试使用 py_compile 编译修改的文件
59
+ if modified_files:
60
+ errors = []
61
+ error_outputs = []
62
+ for file_path in modified_files:
63
+ if not file_path.endswith(".py"):
64
+ continue
65
+ full_path = os.path.join(self.project_root, file_path)
66
+ if os.path.exists(full_path):
67
+ returncode, stdout, stderr = self._run_command(
68
+ ["python", "-m", "py_compile", full_path],
69
+ timeout=5,
70
+ )
71
+ if returncode != 0:
72
+ error_msg = f"{file_path}: {stderr}".strip()
73
+ errors.append(error_msg)
74
+ error_outputs.append(stdout + stderr)
75
+
76
+ if errors:
77
+ duration = time.time() - start_time
78
+ # 合并所有错误输出
79
+ full_output = "\n".join(error_outputs)
80
+ # 提取关键错误信息
81
+ error_message = self._extract_python_errors(full_output)
82
+ if not error_message:
83
+ # 如果没有提取到结构化错误,使用简化的错误列表
84
+ error_message = "\n".join(errors[:5]) # 最多显示5个文件的错误
85
+ if len(errors) > 5:
86
+ error_message += f"\n... 还有 {len(errors) - 5} 个文件存在错误"
87
+ return BuildResult(
88
+ success=False,
89
+ output=full_output,
90
+ error_message=error_message,
91
+ build_system=BuildSystem.PYTHON,
92
+ duration=duration,
93
+ )
94
+
95
+ # 策略2: 尝试运行 pytest --collect-only(如果存在)
96
+ if os.path.exists(os.path.join(self.project_root, "pytest.ini")) or \
97
+ os.path.exists(os.path.join(self.project_root, "setup.py")):
98
+ returncode, stdout, stderr = self._run_command(
99
+ ["python", "-m", "pytest", "--collect-only", "-q"],
100
+ timeout=10,
101
+ )
102
+ duration = time.time() - start_time
103
+ success = returncode == 0
104
+ output = stdout + stderr
105
+ # 如果失败,提取关键错误信息
106
+ if not success:
107
+ error_msg = self._extract_python_errors(output)
108
+ if not error_msg:
109
+ error_msg = "Python项目验证失败"
110
+ else:
111
+ error_msg = None
112
+ return BuildResult(
113
+ success=success,
114
+ output=output,
115
+ error_message=error_msg,
116
+ build_system=BuildSystem.PYTHON,
117
+ duration=duration,
118
+ )
119
+
120
+ # 策略3: 如果没有测试框架,仅验证语法(已在上面的策略1中完成)
121
+ duration = time.time() - start_time
122
+ return BuildResult(
123
+ success=True,
124
+ output="Python语法检查通过",
125
+ error_message=None,
126
+ build_system=BuildSystem.PYTHON,
127
+ duration=duration,
128
+ )
129
+
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ Rust构建验证器模块
6
+
7
+ 提供Rust项目的构建验证功能。
8
+ """
9
+
10
+ import time
11
+ from typing import List, Optional
12
+
13
+ from .base import BuildValidatorBase, BuildResult, BuildSystem
14
+
15
+
16
+ class RustBuildValidator(BuildValidatorBase):
17
+ """Rust构建验证器(使用cargo check)"""
18
+
19
+ def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
20
+ start_time = time.time()
21
+
22
+ # 使用 cargo check 进行增量检查(比 cargo build 更快)
23
+ cmd = ["cargo", "check", "--message-format=json"]
24
+
25
+ returncode, stdout, stderr = self._run_command(cmd)
26
+ duration = time.time() - start_time
27
+
28
+ success = returncode == 0
29
+ output = stdout + stderr
30
+
31
+ if not success:
32
+ # 尝试解析JSON格式的错误信息
33
+ error_message = self._parse_cargo_errors(output)
34
+ else:
35
+ error_message = None
36
+
37
+ return BuildResult(
38
+ success=success,
39
+ output=output,
40
+ error_message=error_message,
41
+ build_system=BuildSystem.RUST,
42
+ duration=duration,
43
+ )
44
+
45
+ def _parse_cargo_errors(self, output: str) -> str:
46
+ """解析cargo的错误输出"""
47
+ # 简化处理:提取关键错误信息
48
+ lines = output.split("\n")
49
+ errors = []
50
+ for line in lines:
51
+ if "error[" in line or "error:" in line.lower():
52
+ errors.append(line.strip())
53
+ return "\n".join(errors[:10]) if errors else output[:500] # 限制长度
54
+
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 构建验证器主模块
6
+
7
+ 提供构建验证器的主类,负责协调各个语言的验证器。
8
+ """
9
+
10
+ from typing import Dict, List, Optional
11
+
12
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
13
+
14
+ from .base import BuildSystem, BuildValidatorBase, BuildResult
15
+ from .detector import BuildSystemDetector
16
+ from .rust import RustBuildValidator
17
+ from .python import PythonBuildValidator
18
+ from .nodejs import NodeJSBuildValidator
19
+ from .java_maven import JavaMavenBuildValidator
20
+ from .java_gradle import JavaGradleBuildValidator
21
+ from .go import GoBuildValidator
22
+ from .cmake import CMakeBuildValidator
23
+ from .makefile import MakefileBuildValidator
24
+ from .fallback import FallbackBuildValidator
25
+
26
+
27
+ class BuildValidator:
28
+ """构建验证器主类"""
29
+
30
+ def __init__(self, project_root: str, timeout: int = 30):
31
+ self.project_root = project_root
32
+ self.timeout = timeout
33
+ self.detector = BuildSystemDetector(project_root)
34
+
35
+ # 导入配置管理器
36
+ from jarvis.jarvis_code_agent.build_validation_config import BuildValidationConfig
37
+ self.config = BuildValidationConfig(project_root)
38
+
39
+ # 注册构建系统验证器
40
+ self._validators: Dict[BuildSystem, BuildValidatorBase] = {
41
+ BuildSystem.RUST: RustBuildValidator(project_root, timeout),
42
+ BuildSystem.PYTHON: PythonBuildValidator(project_root, timeout),
43
+ BuildSystem.NODEJS: NodeJSBuildValidator(project_root, timeout),
44
+ BuildSystem.JAVA_MAVEN: JavaMavenBuildValidator(project_root, timeout),
45
+ BuildSystem.JAVA_GRADLE: JavaGradleBuildValidator(project_root, timeout),
46
+ BuildSystem.GO: GoBuildValidator(project_root, timeout),
47
+ BuildSystem.C_CMAKE: CMakeBuildValidator(project_root, timeout),
48
+ BuildSystem.C_MAKEFILE: MakefileBuildValidator(project_root, timeout),
49
+ BuildSystem.C_MAKEFILE_CMAKE: CMakeBuildValidator(project_root, timeout),
50
+ }
51
+
52
+ # 兜底验证器
53
+ self._fallback_validator = FallbackBuildValidator(project_root, timeout)
54
+
55
+ def _select_build_system(self, detected_systems: List[BuildSystem]) -> Optional[BuildSystem]:
56
+ """让用户选择构建系统
57
+
58
+ Args:
59
+ detected_systems: 检测到的所有构建系统列表
60
+
61
+ Returns:
62
+ 用户选择的构建系统,如果用户取消则返回None
63
+ """
64
+ if not detected_systems:
65
+ return None
66
+
67
+ if len(detected_systems) == 1:
68
+ # 只有一个构建系统,直接返回
69
+ return detected_systems[0]
70
+
71
+ # 检查配置文件中是否已有选择
72
+ saved_system = self.config.get_selected_build_system()
73
+ if saved_system:
74
+ try:
75
+ saved_enum = BuildSystem(saved_system)
76
+ if saved_enum in detected_systems:
77
+ PrettyOutput.print(f"使用配置文件中保存的构建系统: {saved_system}", OutputType.INFO)
78
+ return saved_enum
79
+ except ValueError:
80
+ # 配置文件中保存的构建系统无效,忽略
81
+ pass
82
+
83
+ # 多个构建系统,需要用户选择
84
+ print("\n检测到多个构建系统,请选择要使用的构建系统:")
85
+ for idx, system in enumerate(detected_systems, start=1):
86
+ print(f" {idx}. {system.value}")
87
+ print(f" {len(detected_systems) + 1}. 取消(使用兜底验证器)")
88
+
89
+ while True:
90
+ try:
91
+ choice = input(f"\n请选择 (1-{len(detected_systems) + 1}): ").strip()
92
+ choice_num = int(choice)
93
+
94
+ if 1 <= choice_num <= len(detected_systems):
95
+ selected = detected_systems[choice_num - 1]
96
+ # 保存用户选择
97
+ self.config.set_selected_build_system(selected.value)
98
+ PrettyOutput.print(f"用户选择构建系统: {selected.value}", OutputType.INFO)
99
+ return selected
100
+ elif choice_num == len(detected_systems) + 1:
101
+ PrettyOutput.print("用户取消选择,使用兜底验证器", OutputType.INFO)
102
+ return None
103
+ else:
104
+ print(f"无效选择,请输入 1-{len(detected_systems) + 1}")
105
+ except ValueError:
106
+ print("请输入有效的数字")
107
+ except (KeyboardInterrupt, EOFError):
108
+ print("\n用户取消,使用兜底验证器")
109
+ return None
110
+
111
+ def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
112
+ """验证构建
113
+
114
+ Args:
115
+ modified_files: 修改的文件列表(可选,用于增量验证)
116
+
117
+ Returns:
118
+ BuildResult: 验证结果
119
+ """
120
+ # 检测所有可能的构建系统
121
+ detected_systems = self.detector.detect_all()
122
+
123
+ if not detected_systems:
124
+ # 未检测到构建系统,使用兜底验证器
125
+ PrettyOutput.print("未检测到构建系统,使用兜底验证器", OutputType.INFO)
126
+ return self._fallback_validator.validate(modified_files)
127
+
128
+ # 让用户选择构建系统(如果多个)
129
+ build_system = self._select_build_system(detected_systems)
130
+
131
+ if build_system and build_system in self._validators:
132
+ validator = self._validators[build_system]
133
+ PrettyOutput.print(f"使用构建系统: {build_system.value}, 验证器: {validator.__class__.__name__}", OutputType.INFO)
134
+ try:
135
+ return validator.validate(modified_files)
136
+ except Exception as e:
137
+ PrettyOutput.print(f"验证器 {validator.__class__.__name__} 执行失败: {e}, 使用兜底验证器", OutputType.WARNING)
138
+ # 验证器执行失败时,使用兜底验证器
139
+ return self._fallback_validator.validate(modified_files)
140
+ else:
141
+ # 用户取消或未选择,使用兜底验证器
142
+ PrettyOutput.print("使用兜底验证器", OutputType.INFO)
143
+ return self._fallback_validator.validate(modified_files)
144
+
145
+ def register_validator(self, build_system: BuildSystem, validator: BuildValidatorBase):
146
+ """注册自定义验证器(扩展点)
147
+
148
+ Args:
149
+ build_system: 构建系统类型
150
+ validator: 验证器实例
151
+ """
152
+ self._validators[build_system] = validator
153
+ PrettyOutput.print(f"注册自定义验证器: {build_system.value} -> {validator.__class__.__name__}", OutputType.INFO)
154
+
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 构建验证模块(向后兼容导入)
6
+
7
+ 此文件保持向后兼容,实际实现已迁移到 build_validator 包中。
8
+ """
9
+
10
+ # 从新模块导入所有内容,保持向后兼容
11
+ from jarvis.jarvis_code_agent.code_analyzer.build_validator import (
12
+ BuildSystem,
13
+ BuildResult,
14
+ BuildValidatorBase,
15
+ BuildSystemDetector,
16
+ BuildValidator,
17
+ RustBuildValidator,
18
+ PythonBuildValidator,
19
+ NodeJSBuildValidator,
20
+ JavaMavenBuildValidator,
21
+ JavaGradleBuildValidator,
22
+ GoBuildValidator,
23
+ CMakeBuildValidator,
24
+ MakefileBuildValidator,
25
+ FallbackBuildValidator,
26
+ )
27
+
28
+ __all__ = [
29
+ "BuildSystem",
30
+ "BuildResult",
31
+ "BuildValidatorBase",
32
+ "BuildSystemDetector",
33
+ "BuildValidator",
34
+ "RustBuildValidator",
35
+ "PythonBuildValidator",
36
+ "NodeJSBuildValidator",
37
+ "JavaMavenBuildValidator",
38
+ "JavaGradleBuildValidator",
39
+ "GoBuildValidator",
40
+ "CMakeBuildValidator",
41
+ "MakefileBuildValidator",
42
+ "FallbackBuildValidator",
43
+ ]