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.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +1143 -245
- jarvis/jarvis_agent/agent_manager.py +97 -0
- jarvis/jarvis_agent/builtin_input_handler.py +12 -10
- jarvis/jarvis_agent/config_editor.py +57 -0
- jarvis/jarvis_agent/edit_file_handler.py +392 -99
- jarvis/jarvis_agent/event_bus.py +48 -0
- jarvis/jarvis_agent/events.py +157 -0
- jarvis/jarvis_agent/file_context_handler.py +79 -0
- jarvis/jarvis_agent/file_methodology_manager.py +117 -0
- jarvis/jarvis_agent/jarvis.py +1117 -147
- jarvis/jarvis_agent/main.py +78 -34
- jarvis/jarvis_agent/memory_manager.py +195 -0
- jarvis/jarvis_agent/methodology_share_manager.py +174 -0
- jarvis/jarvis_agent/prompt_manager.py +82 -0
- jarvis/jarvis_agent/prompts.py +46 -9
- jarvis/jarvis_agent/protocols.py +4 -1
- jarvis/jarvis_agent/rewrite_file_handler.py +141 -0
- jarvis/jarvis_agent/run_loop.py +146 -0
- jarvis/jarvis_agent/session_manager.py +9 -9
- jarvis/jarvis_agent/share_manager.py +228 -0
- jarvis/jarvis_agent/shell_input_handler.py +23 -3
- jarvis/jarvis_agent/stdio_redirect.py +295 -0
- jarvis/jarvis_agent/task_analyzer.py +212 -0
- jarvis/jarvis_agent/task_manager.py +154 -0
- jarvis/jarvis_agent/task_planner.py +496 -0
- jarvis/jarvis_agent/tool_executor.py +8 -4
- jarvis/jarvis_agent/tool_share_manager.py +139 -0
- jarvis/jarvis_agent/user_interaction.py +42 -0
- jarvis/jarvis_agent/utils.py +54 -0
- jarvis/jarvis_agent/web_bridge.py +189 -0
- jarvis/jarvis_agent/web_output_sink.py +53 -0
- jarvis/jarvis_agent/web_server.py +751 -0
- jarvis/jarvis_c2rust/__init__.py +26 -0
- jarvis/jarvis_c2rust/cli.py +613 -0
- jarvis/jarvis_c2rust/collector.py +258 -0
- jarvis/jarvis_c2rust/library_replacer.py +1122 -0
- jarvis/jarvis_c2rust/llm_module_agent.py +1300 -0
- jarvis/jarvis_c2rust/optimizer.py +960 -0
- jarvis/jarvis_c2rust/scanner.py +1681 -0
- jarvis/jarvis_c2rust/transpiler.py +2325 -0
- jarvis/jarvis_code_agent/build_validation_config.py +133 -0
- jarvis/jarvis_code_agent/code_agent.py +1605 -178
- jarvis/jarvis_code_agent/code_analyzer/__init__.py +62 -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 +102 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +59 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +125 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +69 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +38 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +44 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +38 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +50 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +93 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +129 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +54 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +154 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator.py +43 -0
- jarvis/jarvis_code_agent/code_analyzer/context_manager.py +363 -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 +89 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +31 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +231 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +183 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +219 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +209 -0
- jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +451 -0
- jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +77 -0
- jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +48 -0
- jarvis/jarvis_code_agent/lint.py +275 -13
- jarvis/jarvis_code_agent/utils.py +142 -0
- jarvis/jarvis_code_analysis/checklists/loader.py +20 -6
- jarvis/jarvis_code_analysis/code_review.py +583 -548
- jarvis/jarvis_data/config_schema.json +339 -28
- jarvis/jarvis_git_squash/main.py +22 -13
- jarvis/jarvis_git_utils/git_commiter.py +171 -55
- jarvis/jarvis_mcp/sse_mcp_client.py +22 -15
- jarvis/jarvis_mcp/stdio_mcp_client.py +4 -4
- jarvis/jarvis_mcp/streamable_mcp_client.py +36 -16
- jarvis/jarvis_memory_organizer/memory_organizer.py +753 -0
- jarvis/jarvis_methodology/main.py +48 -63
- jarvis/jarvis_multi_agent/__init__.py +302 -43
- jarvis/jarvis_multi_agent/main.py +70 -24
- jarvis/jarvis_platform/ai8.py +40 -23
- jarvis/jarvis_platform/base.py +210 -49
- jarvis/jarvis_platform/human.py +11 -1
- jarvis/jarvis_platform/kimi.py +82 -76
- jarvis/jarvis_platform/openai.py +73 -1
- jarvis/jarvis_platform/registry.py +8 -15
- jarvis/jarvis_platform/tongyi.py +115 -101
- jarvis/jarvis_platform/yuanbao.py +89 -63
- jarvis/jarvis_platform_manager/main.py +194 -132
- jarvis/jarvis_platform_manager/service.py +122 -86
- jarvis/jarvis_rag/cli.py +156 -53
- jarvis/jarvis_rag/embedding_manager.py +155 -12
- jarvis/jarvis_rag/llm_interface.py +10 -13
- jarvis/jarvis_rag/query_rewriter.py +63 -12
- jarvis/jarvis_rag/rag_pipeline.py +222 -40
- jarvis/jarvis_rag/reranker.py +26 -3
- jarvis/jarvis_rag/retriever.py +270 -14
- jarvis/jarvis_sec/__init__.py +3605 -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 +116 -0
- jarvis/jarvis_sec/report.py +257 -0
- jarvis/jarvis_sec/status.py +264 -0
- jarvis/jarvis_sec/types.py +20 -0
- jarvis/jarvis_sec/workflow.py +219 -0
- jarvis/jarvis_smart_shell/main.py +405 -137
- jarvis/jarvis_stats/__init__.py +13 -0
- jarvis/jarvis_stats/cli.py +387 -0
- jarvis/jarvis_stats/stats.py +711 -0
- jarvis/jarvis_stats/storage.py +612 -0
- jarvis/jarvis_stats/visualizer.py +282 -0
- jarvis/jarvis_tools/ask_user.py +1 -0
- jarvis/jarvis_tools/base.py +18 -2
- jarvis/jarvis_tools/clear_memory.py +239 -0
- jarvis/jarvis_tools/cli/main.py +220 -144
- jarvis/jarvis_tools/execute_script.py +52 -12
- jarvis/jarvis_tools/file_analyzer.py +17 -12
- jarvis/jarvis_tools/generate_new_tool.py +46 -24
- jarvis/jarvis_tools/read_code.py +277 -18
- jarvis/jarvis_tools/read_symbols.py +141 -0
- jarvis/jarvis_tools/read_webpage.py +86 -13
- jarvis/jarvis_tools/registry.py +294 -90
- jarvis/jarvis_tools/retrieve_memory.py +227 -0
- jarvis/jarvis_tools/save_memory.py +194 -0
- jarvis/jarvis_tools/search_web.py +62 -28
- jarvis/jarvis_tools/sub_agent.py +205 -0
- jarvis/jarvis_tools/sub_code_agent.py +217 -0
- jarvis/jarvis_tools/virtual_tty.py +330 -62
- jarvis/jarvis_utils/builtin_replace_map.py +4 -5
- jarvis/jarvis_utils/clipboard.py +90 -0
- jarvis/jarvis_utils/config.py +607 -50
- jarvis/jarvis_utils/embedding.py +3 -0
- jarvis/jarvis_utils/fzf.py +57 -0
- jarvis/jarvis_utils/git_utils.py +251 -29
- jarvis/jarvis_utils/globals.py +174 -17
- jarvis/jarvis_utils/http.py +58 -79
- jarvis/jarvis_utils/input.py +899 -153
- jarvis/jarvis_utils/methodology.py +210 -83
- jarvis/jarvis_utils/output.py +220 -137
- jarvis/jarvis_utils/utils.py +1906 -135
- jarvis_ai_assistant-0.7.0.dist-info/METADATA +465 -0
- jarvis_ai_assistant-0.7.0.dist-info/RECORD +192 -0
- {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/entry_points.txt +8 -2
- jarvis/jarvis_git_details/main.py +0 -265
- jarvis/jarvis_platform/oyi.py +0 -357
- jarvis/jarvis_tools/edit_file.py +0 -255
- jarvis/jarvis_tools/rewrite_file.py +0 -195
- jarvis_ai_assistant-0.1.222.dist-info/METADATA +0 -767
- jarvis_ai_assistant-0.1.222.dist-info/RECORD +0 -110
- /jarvis/{jarvis_git_details → jarvis_memory_organizer}/__init__.py +0 -0
- {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.222.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Jarvis代码分析器模块。
|
|
2
|
+
|
|
3
|
+
提供符号提取、依赖分析和上下文管理功能。
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from .symbol_extractor import Symbol, SymbolTable, SymbolExtractor
|
|
7
|
+
from .dependency_analyzer import Dependency, DependencyGraph, DependencyAnalyzer
|
|
8
|
+
from .context_manager import ContextManager, EditContext, Reference
|
|
9
|
+
from .context_recommender import ContextRecommendation
|
|
10
|
+
from .llm_context_recommender import ContextRecommender
|
|
11
|
+
from .language_support import detect_language, get_symbol_extractor, get_dependency_analyzer
|
|
12
|
+
from .base_language import BaseLanguageSupport
|
|
13
|
+
from .language_registry import LanguageRegistry, get_registry, register_language
|
|
14
|
+
from .impact_analyzer import (
|
|
15
|
+
ImpactAnalyzer,
|
|
16
|
+
Impact,
|
|
17
|
+
ImpactReport,
|
|
18
|
+
ImpactType,
|
|
19
|
+
RiskLevel,
|
|
20
|
+
InterfaceChange,
|
|
21
|
+
Edit,
|
|
22
|
+
TestDiscoverer,
|
|
23
|
+
parse_git_diff_to_edits,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
# Symbol extraction
|
|
28
|
+
'Symbol',
|
|
29
|
+
'SymbolTable',
|
|
30
|
+
'SymbolExtractor',
|
|
31
|
+
# Dependency analysis
|
|
32
|
+
'Dependency',
|
|
33
|
+
'DependencyGraph',
|
|
34
|
+
'DependencyAnalyzer',
|
|
35
|
+
# Context management
|
|
36
|
+
'ContextManager',
|
|
37
|
+
'EditContext',
|
|
38
|
+
'Reference',
|
|
39
|
+
# Context recommendation
|
|
40
|
+
'ContextRecommender',
|
|
41
|
+
'ContextRecommendation',
|
|
42
|
+
# Language support
|
|
43
|
+
'detect_language',
|
|
44
|
+
'get_symbol_extractor',
|
|
45
|
+
'get_dependency_analyzer',
|
|
46
|
+
# Language registry
|
|
47
|
+
'BaseLanguageSupport',
|
|
48
|
+
'LanguageRegistry',
|
|
49
|
+
'get_registry',
|
|
50
|
+
'register_language',
|
|
51
|
+
# Impact analysis
|
|
52
|
+
'ImpactAnalyzer',
|
|
53
|
+
'Impact',
|
|
54
|
+
'ImpactReport',
|
|
55
|
+
'ImpactType',
|
|
56
|
+
'RiskLevel',
|
|
57
|
+
'InterfaceChange',
|
|
58
|
+
'Edit',
|
|
59
|
+
'TestDiscoverer',
|
|
60
|
+
'parse_git_diff_to_edits',
|
|
61
|
+
]
|
|
62
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""基础语言支持抽象类。
|
|
2
|
+
|
|
3
|
+
定义所有语言支持需要实现的接口,便于扩展新的语言支持。
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
from typing import Optional, Set
|
|
8
|
+
|
|
9
|
+
from .dependency_analyzer import DependencyAnalyzer
|
|
10
|
+
from .symbol_extractor import SymbolExtractor
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BaseLanguageSupport(ABC):
|
|
14
|
+
"""语言支持的基础抽象类。
|
|
15
|
+
|
|
16
|
+
所有语言支持类都应该继承此类并实现所需的方法。
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def language_name(self) -> str:
|
|
22
|
+
"""返回语言名称(如 'python', 'rust', 'go')。"""
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
@abstractmethod
|
|
27
|
+
def file_extensions(self) -> Set[str]:
|
|
28
|
+
"""返回该语言支持的文件扩展名集合(如 {'.py', '.pyw'})。"""
|
|
29
|
+
pass
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def create_symbol_extractor(self) -> Optional[SymbolExtractor]:
|
|
33
|
+
"""创建并返回该语言的符号提取器实例。
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
SymbolExtractor实例,如果不支持符号提取则返回None
|
|
37
|
+
"""
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
@abstractmethod
|
|
41
|
+
def create_dependency_analyzer(self) -> Optional[DependencyAnalyzer]:
|
|
42
|
+
"""创建并返回该语言的依赖分析器实例。
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
DependencyAnalyzer实例,如果不支持依赖分析则返回None
|
|
46
|
+
"""
|
|
47
|
+
pass
|
|
48
|
+
|
|
49
|
+
def is_source_file(self, file_path: str) -> bool:
|
|
50
|
+
"""检查文件是否为该语言的源文件。
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
file_path: 文件路径
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
如果是该语言的源文件返回True,否则返回False
|
|
57
|
+
"""
|
|
58
|
+
import os
|
|
59
|
+
_, ext = os.path.splitext(file_path)
|
|
60
|
+
return ext in self.file_extensions
|
|
61
|
+
|
|
62
|
+
def detect_language(self, file_path: str) -> Optional[str]:
|
|
63
|
+
"""检测文件是否属于该语言。
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
file_path: 文件路径
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
如果属于该语言返回language_name,否则返回None
|
|
70
|
+
"""
|
|
71
|
+
if self.is_source_file(file_path):
|
|
72
|
+
return self.language_name
|
|
73
|
+
return None
|
|
74
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
构建验证模块
|
|
6
|
+
|
|
7
|
+
提供编辑后编译/构建验证功能,支持多种构建系统,具有易扩展性和兜底机制。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
# 导出主要接口
|
|
11
|
+
from .base import BuildSystem, BuildResult, BuildValidatorBase
|
|
12
|
+
from .detector import BuildSystemDetector
|
|
13
|
+
from .validator import BuildValidator
|
|
14
|
+
|
|
15
|
+
# 导出各语言验证器(便于扩展)
|
|
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
|
+
__all__ = [
|
|
27
|
+
# 主要接口
|
|
28
|
+
"BuildSystem",
|
|
29
|
+
"BuildResult",
|
|
30
|
+
"BuildValidatorBase",
|
|
31
|
+
"BuildSystemDetector",
|
|
32
|
+
"BuildValidator",
|
|
33
|
+
# 各语言验证器
|
|
34
|
+
"RustBuildValidator",
|
|
35
|
+
"PythonBuildValidator",
|
|
36
|
+
"NodeJSBuildValidator",
|
|
37
|
+
"JavaMavenBuildValidator",
|
|
38
|
+
"JavaGradleBuildValidator",
|
|
39
|
+
"GoBuildValidator",
|
|
40
|
+
"CMakeBuildValidator",
|
|
41
|
+
"MakefileBuildValidator",
|
|
42
|
+
"FallbackBuildValidator",
|
|
43
|
+
]
|
|
44
|
+
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
构建验证器基础模块
|
|
6
|
+
|
|
7
|
+
提供基础类和枚举定义。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import subprocess
|
|
11
|
+
from abc import ABC, abstractmethod
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from typing import List, Optional, Tuple
|
|
14
|
+
from enum import Enum
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class BuildSystem(Enum):
|
|
18
|
+
"""支持的构建系统类型"""
|
|
19
|
+
UNKNOWN = "unknown"
|
|
20
|
+
PYTHON = "python"
|
|
21
|
+
NODEJS = "nodejs"
|
|
22
|
+
RUST = "rust"
|
|
23
|
+
JAVA_MAVEN = "java_maven"
|
|
24
|
+
JAVA_GRADLE = "java_gradle"
|
|
25
|
+
GO = "go"
|
|
26
|
+
C_MAKEFILE = "c_makefile"
|
|
27
|
+
C_CMAKE = "c_cmake"
|
|
28
|
+
C_MAKEFILE_CMAKE = "c_makefile_cmake" # 同时存在Makefile和CMakeLists.txt
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass
|
|
32
|
+
class BuildResult:
|
|
33
|
+
"""构建验证结果"""
|
|
34
|
+
success: bool
|
|
35
|
+
output: str
|
|
36
|
+
error_message: Optional[str] = None
|
|
37
|
+
build_system: Optional[BuildSystem] = None
|
|
38
|
+
duration: float = 0.0 # 验证耗时(秒)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class BuildValidatorBase(ABC):
|
|
42
|
+
"""构建验证器基类"""
|
|
43
|
+
|
|
44
|
+
def __init__(self, project_root: str, timeout: int = 30):
|
|
45
|
+
self.project_root = project_root
|
|
46
|
+
self.timeout = timeout
|
|
47
|
+
|
|
48
|
+
@abstractmethod
|
|
49
|
+
def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
|
|
50
|
+
"""验证构建
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
modified_files: 修改的文件列表(可选,用于增量验证)
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
BuildResult: 验证结果
|
|
57
|
+
"""
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
def _run_command(
|
|
61
|
+
self,
|
|
62
|
+
cmd: List[str],
|
|
63
|
+
cwd: Optional[str] = None,
|
|
64
|
+
timeout: Optional[int] = None,
|
|
65
|
+
capture_output: bool = True,
|
|
66
|
+
) -> Tuple[int, str, str]:
|
|
67
|
+
"""运行命令
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
cmd: 命令列表
|
|
71
|
+
cwd: 工作目录
|
|
72
|
+
timeout: 超时时间(秒)
|
|
73
|
+
capture_output: 是否捕获输出
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
(返回码, stdout, stderr)
|
|
77
|
+
"""
|
|
78
|
+
if cwd is None:
|
|
79
|
+
cwd = self.project_root
|
|
80
|
+
if timeout is None:
|
|
81
|
+
timeout = self.timeout
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
result = subprocess.run(
|
|
85
|
+
cmd,
|
|
86
|
+
cwd=cwd,
|
|
87
|
+
timeout=timeout,
|
|
88
|
+
capture_output=capture_output,
|
|
89
|
+
text=True,
|
|
90
|
+
encoding="utf-8",
|
|
91
|
+
errors="replace",
|
|
92
|
+
)
|
|
93
|
+
stdout = result.stdout if capture_output else ""
|
|
94
|
+
stderr = result.stderr if capture_output else ""
|
|
95
|
+
return result.returncode, stdout, stderr
|
|
96
|
+
except subprocess.TimeoutExpired:
|
|
97
|
+
return -1, "", f"命令执行超时({timeout}秒)"
|
|
98
|
+
except FileNotFoundError:
|
|
99
|
+
return -1, "", f"命令未找到: {cmd[0]}"
|
|
100
|
+
except Exception as e:
|
|
101
|
+
return -1, "", f"执行命令时出错: {str(e)}"
|
|
102
|
+
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
CMake构建验证器模块
|
|
6
|
+
|
|
7
|
+
提供CMake项目的构建验证功能。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import tempfile
|
|
12
|
+
import time
|
|
13
|
+
from typing import List, Optional
|
|
14
|
+
|
|
15
|
+
from .base import BuildValidatorBase, BuildResult, BuildSystem
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CMakeBuildValidator(BuildValidatorBase):
|
|
19
|
+
"""CMake构建验证器"""
|
|
20
|
+
|
|
21
|
+
def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
|
|
22
|
+
start_time = time.time()
|
|
23
|
+
|
|
24
|
+
# 策略1: 尝试使用 cmake --build(如果已有构建目录)
|
|
25
|
+
build_dirs = ["build", "cmake-build-debug", "cmake-build-release"]
|
|
26
|
+
for build_dir in build_dirs:
|
|
27
|
+
build_path = os.path.join(self.project_root, build_dir)
|
|
28
|
+
if os.path.exists(build_path):
|
|
29
|
+
returncode, stdout, stderr = self._run_command(
|
|
30
|
+
["cmake", "--build", build_path],
|
|
31
|
+
timeout=60,
|
|
32
|
+
)
|
|
33
|
+
duration = time.time() - start_time
|
|
34
|
+
success = returncode == 0
|
|
35
|
+
return BuildResult(
|
|
36
|
+
success=success,
|
|
37
|
+
output=stdout + stderr,
|
|
38
|
+
error_message=None if success else "CMake构建失败",
|
|
39
|
+
build_system=BuildSystem.C_CMAKE,
|
|
40
|
+
duration=duration,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# 策略2: 仅验证CMakeLists.txt语法
|
|
44
|
+
with tempfile.TemporaryDirectory(prefix="cmake_check_") as tmpdir:
|
|
45
|
+
returncode, stdout, stderr = self._run_command(
|
|
46
|
+
["cmake", "-S", ".", "-B", tmpdir],
|
|
47
|
+
timeout=10,
|
|
48
|
+
)
|
|
49
|
+
duration = time.time() - start_time
|
|
50
|
+
|
|
51
|
+
success = returncode == 0
|
|
52
|
+
return BuildResult(
|
|
53
|
+
success=success,
|
|
54
|
+
output=stdout + stderr,
|
|
55
|
+
error_message=None if success else "CMake配置失败",
|
|
56
|
+
build_system=BuildSystem.C_CMAKE,
|
|
57
|
+
duration=duration,
|
|
58
|
+
)
|
|
59
|
+
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
构建系统检测器模块
|
|
6
|
+
|
|
7
|
+
提供构建系统自动检测功能。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
from typing import List, Optional
|
|
12
|
+
|
|
13
|
+
from .base import BuildSystem
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BuildSystemDetector:
|
|
17
|
+
"""构建系统检测器"""
|
|
18
|
+
|
|
19
|
+
def __init__(self, project_root: str):
|
|
20
|
+
self.project_root = project_root
|
|
21
|
+
|
|
22
|
+
def detect(self) -> Optional[BuildSystem]:
|
|
23
|
+
"""检测项目使用的构建系统(兼容旧接口,返回第一个检测到的)
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
检测到的构建系统,如果无法检测则返回None
|
|
27
|
+
"""
|
|
28
|
+
all_systems = self.detect_all()
|
|
29
|
+
return all_systems[0] if all_systems else None
|
|
30
|
+
|
|
31
|
+
def detect_all(self) -> List[BuildSystem]:
|
|
32
|
+
"""检测所有可能的构建系统
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
检测到的所有构建系统列表(按优先级排序)
|
|
36
|
+
"""
|
|
37
|
+
detected = []
|
|
38
|
+
# 按优先级检测(从最具体到最通用)
|
|
39
|
+
detectors = [
|
|
40
|
+
self._detect_rust,
|
|
41
|
+
self._detect_go,
|
|
42
|
+
self._detect_java_maven,
|
|
43
|
+
self._detect_java_gradle,
|
|
44
|
+
self._detect_nodejs,
|
|
45
|
+
self._detect_python,
|
|
46
|
+
self._detect_c_cmake,
|
|
47
|
+
self._detect_c_makefile,
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
for detector in detectors:
|
|
51
|
+
result = detector()
|
|
52
|
+
if result and result not in detected:
|
|
53
|
+
detected.append(result)
|
|
54
|
+
|
|
55
|
+
return detected
|
|
56
|
+
|
|
57
|
+
def _detect_rust(self) -> Optional[BuildSystem]:
|
|
58
|
+
"""检测Rust项目(Cargo.toml)"""
|
|
59
|
+
cargo_toml = os.path.join(self.project_root, "Cargo.toml")
|
|
60
|
+
if os.path.exists(cargo_toml):
|
|
61
|
+
return BuildSystem.RUST
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
def _detect_go(self) -> Optional[BuildSystem]:
|
|
65
|
+
"""检测Go项目(go.mod)"""
|
|
66
|
+
go_mod = os.path.join(self.project_root, "go.mod")
|
|
67
|
+
if os.path.exists(go_mod):
|
|
68
|
+
return BuildSystem.GO
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
def _detect_java_maven(self) -> Optional[BuildSystem]:
|
|
72
|
+
"""检测Maven项目(pom.xml)"""
|
|
73
|
+
pom_xml = os.path.join(self.project_root, "pom.xml")
|
|
74
|
+
if os.path.exists(pom_xml):
|
|
75
|
+
return BuildSystem.JAVA_MAVEN
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
def _detect_java_gradle(self) -> Optional[BuildSystem]:
|
|
79
|
+
"""检测Gradle项目(build.gradle或build.gradle.kts)"""
|
|
80
|
+
build_gradle = os.path.join(self.project_root, "build.gradle")
|
|
81
|
+
build_gradle_kts = os.path.join(self.project_root, "build.gradle.kts")
|
|
82
|
+
if os.path.exists(build_gradle) or os.path.exists(build_gradle_kts):
|
|
83
|
+
return BuildSystem.JAVA_GRADLE
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
def _detect_nodejs(self) -> Optional[BuildSystem]:
|
|
87
|
+
"""检测Node.js项目(package.json)"""
|
|
88
|
+
package_json = os.path.join(self.project_root, "package.json")
|
|
89
|
+
if os.path.exists(package_json):
|
|
90
|
+
return BuildSystem.NODEJS
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
def _detect_python(self) -> Optional[BuildSystem]:
|
|
94
|
+
"""检测Python项目(setup.py, pyproject.toml, requirements.txt等)"""
|
|
95
|
+
indicators = [
|
|
96
|
+
"setup.py",
|
|
97
|
+
"pyproject.toml",
|
|
98
|
+
"requirements.txt",
|
|
99
|
+
"setup.cfg",
|
|
100
|
+
"Pipfile",
|
|
101
|
+
"poetry.lock",
|
|
102
|
+
]
|
|
103
|
+
for indicator in indicators:
|
|
104
|
+
if os.path.exists(os.path.join(self.project_root, indicator)):
|
|
105
|
+
return BuildSystem.PYTHON
|
|
106
|
+
return None
|
|
107
|
+
|
|
108
|
+
def _detect_c_cmake(self) -> Optional[BuildSystem]:
|
|
109
|
+
"""检测CMake项目(CMakeLists.txt)"""
|
|
110
|
+
cmake_lists = os.path.join(self.project_root, "CMakeLists.txt")
|
|
111
|
+
if os.path.exists(cmake_lists):
|
|
112
|
+
# 检查是否同时存在Makefile
|
|
113
|
+
makefile = os.path.join(self.project_root, "Makefile")
|
|
114
|
+
if os.path.exists(makefile):
|
|
115
|
+
return BuildSystem.C_MAKEFILE_CMAKE
|
|
116
|
+
return BuildSystem.C_CMAKE
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
def _detect_c_makefile(self) -> Optional[BuildSystem]:
|
|
120
|
+
"""检测Makefile项目"""
|
|
121
|
+
makefile = os.path.join(self.project_root, "Makefile")
|
|
122
|
+
if os.path.exists(makefile):
|
|
123
|
+
return BuildSystem.C_MAKEFILE
|
|
124
|
+
return None
|
|
125
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
兜底构建验证器模块
|
|
6
|
+
|
|
7
|
+
当无法检测构建系统时使用的兜底验证器。
|
|
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 FallbackBuildValidator(BuildValidatorBase):
|
|
18
|
+
"""兜底验证器:当无法检测构建系统时使用"""
|
|
19
|
+
|
|
20
|
+
def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
|
|
21
|
+
start_time = time.time()
|
|
22
|
+
|
|
23
|
+
# 策略1: 根据文件扩展名进行基本的语法检查
|
|
24
|
+
if modified_files:
|
|
25
|
+
errors = []
|
|
26
|
+
for file_path in modified_files:
|
|
27
|
+
ext = os.path.splitext(file_path)[1].lower()
|
|
28
|
+
full_path = os.path.join(self.project_root, file_path)
|
|
29
|
+
|
|
30
|
+
if not os.path.exists(full_path):
|
|
31
|
+
continue
|
|
32
|
+
|
|
33
|
+
# Python文件:使用py_compile
|
|
34
|
+
if ext == ".py":
|
|
35
|
+
returncode, _, stderr = self._run_command(
|
|
36
|
+
["python", "-m", "py_compile", full_path],
|
|
37
|
+
timeout=5,
|
|
38
|
+
)
|
|
39
|
+
if returncode != 0:
|
|
40
|
+
errors.append(f"{file_path}: {stderr}")
|
|
41
|
+
|
|
42
|
+
# JavaScript文件:尝试使用node检查语法
|
|
43
|
+
elif ext in (".js", ".mjs", ".cjs"):
|
|
44
|
+
returncode, _, stderr = self._run_command(
|
|
45
|
+
["node", "--check", full_path],
|
|
46
|
+
timeout=5,
|
|
47
|
+
)
|
|
48
|
+
if returncode != 0:
|
|
49
|
+
errors.append(f"{file_path}: {stderr}")
|
|
50
|
+
|
|
51
|
+
if errors:
|
|
52
|
+
duration = time.time() - start_time
|
|
53
|
+
return BuildResult(
|
|
54
|
+
success=False,
|
|
55
|
+
output="\n".join(errors),
|
|
56
|
+
error_message="语法检查失败",
|
|
57
|
+
build_system=BuildSystem.UNKNOWN,
|
|
58
|
+
duration=duration,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
duration = time.time() - start_time
|
|
62
|
+
return BuildResult(
|
|
63
|
+
success=True,
|
|
64
|
+
output="基础语法检查通过(未检测到构建系统)",
|
|
65
|
+
error_message=None,
|
|
66
|
+
build_system=BuildSystem.UNKNOWN,
|
|
67
|
+
duration=duration,
|
|
68
|
+
)
|
|
69
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Go构建验证器模块
|
|
6
|
+
|
|
7
|
+
提供Go项目的构建验证功能。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import time
|
|
11
|
+
from typing import List, Optional
|
|
12
|
+
|
|
13
|
+
from .base import BuildValidatorBase, BuildResult, BuildSystem
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class GoBuildValidator(BuildValidatorBase):
|
|
17
|
+
"""Go构建验证器"""
|
|
18
|
+
|
|
19
|
+
def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
|
|
20
|
+
start_time = time.time()
|
|
21
|
+
|
|
22
|
+
# 使用 go build 进行构建验证
|
|
23
|
+
cmd = ["go", "build", "./..."]
|
|
24
|
+
|
|
25
|
+
returncode, stdout, stderr = self._run_command(cmd, timeout=30)
|
|
26
|
+
duration = time.time() - start_time
|
|
27
|
+
|
|
28
|
+
success = returncode == 0
|
|
29
|
+
output = stdout + stderr
|
|
30
|
+
|
|
31
|
+
return BuildResult(
|
|
32
|
+
success=success,
|
|
33
|
+
output=output,
|
|
34
|
+
error_message=None if success else "Go构建失败",
|
|
35
|
+
build_system=BuildSystem.GO,
|
|
36
|
+
duration=duration,
|
|
37
|
+
)
|
|
38
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Java Gradle构建验证器模块
|
|
6
|
+
|
|
7
|
+
提供Java Gradle项目的构建验证功能。
|
|
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 JavaGradleBuildValidator(BuildValidatorBase):
|
|
18
|
+
"""Java Gradle构建验证器"""
|
|
19
|
+
|
|
20
|
+
def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
|
|
21
|
+
start_time = time.time()
|
|
22
|
+
|
|
23
|
+
# 使用 gradle compileJava 进行编译验证
|
|
24
|
+
# 优先使用 gradlew(如果存在)
|
|
25
|
+
gradlew = os.path.join(self.project_root, "gradlew")
|
|
26
|
+
if os.path.exists(gradlew):
|
|
27
|
+
cmd = ["./gradlew", "compileJava", "--quiet"]
|
|
28
|
+
else:
|
|
29
|
+
cmd = ["gradle", "compileJava", "--quiet"]
|
|
30
|
+
|
|
31
|
+
returncode, stdout, stderr = self._run_command(cmd, timeout=60)
|
|
32
|
+
duration = time.time() - start_time
|
|
33
|
+
|
|
34
|
+
success = returncode == 0
|
|
35
|
+
output = stdout + stderr
|
|
36
|
+
|
|
37
|
+
return BuildResult(
|
|
38
|
+
success=success,
|
|
39
|
+
output=output,
|
|
40
|
+
error_message=None if success else "Gradle编译失败",
|
|
41
|
+
build_system=BuildSystem.JAVA_GRADLE,
|
|
42
|
+
duration=duration,
|
|
43
|
+
)
|
|
44
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Java Maven构建验证器模块
|
|
6
|
+
|
|
7
|
+
提供Java Maven项目的构建验证功能。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import time
|
|
11
|
+
from typing import List, Optional
|
|
12
|
+
|
|
13
|
+
from .base import BuildValidatorBase, BuildResult, BuildSystem
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class JavaMavenBuildValidator(BuildValidatorBase):
|
|
17
|
+
"""Java Maven构建验证器"""
|
|
18
|
+
|
|
19
|
+
def validate(self, modified_files: Optional[List[str]] = None) -> BuildResult:
|
|
20
|
+
start_time = time.time()
|
|
21
|
+
|
|
22
|
+
# 使用 mvn compile 进行编译验证
|
|
23
|
+
cmd = ["mvn", "compile", "-q"] # -q 静默模式
|
|
24
|
+
|
|
25
|
+
returncode, stdout, stderr = self._run_command(cmd, timeout=60)
|
|
26
|
+
duration = time.time() - start_time
|
|
27
|
+
|
|
28
|
+
success = returncode == 0
|
|
29
|
+
output = stdout + stderr
|
|
30
|
+
|
|
31
|
+
return BuildResult(
|
|
32
|
+
success=success,
|
|
33
|
+
output=output,
|
|
34
|
+
error_message=None if success else "Maven编译失败",
|
|
35
|
+
build_system=BuildSystem.JAVA_MAVEN,
|
|
36
|
+
duration=duration,
|
|
37
|
+
)
|
|
38
|
+
|