jarvis-ai-assistant 0.4.2__py3-none-any.whl → 0.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +117 -6
- jarvis/jarvis_agent/jarvis.py +6 -0
- jarvis/jarvis_agent/share_manager.py +8 -1
- jarvis/jarvis_agent/task_planner.py +218 -0
- jarvis/jarvis_code_agent/code_agent.py +99 -3
- jarvis/jarvis_code_analysis/code_review.py +483 -568
- jarvis/jarvis_data/config_schema.json +8 -3
- jarvis/jarvis_sec/README.md +180 -0
- jarvis/jarvis_sec/__init__.py +674 -0
- jarvis/jarvis_sec/checkers/__init__.py +33 -0
- jarvis/jarvis_sec/checkers/c_checker.py +1269 -0
- jarvis/jarvis_sec/checkers/rust_checker.py +367 -0
- jarvis/jarvis_sec/cli.py +110 -0
- jarvis/jarvis_sec/prompts.py +324 -0
- jarvis/jarvis_sec/report.py +260 -0
- jarvis/jarvis_sec/types.py +20 -0
- jarvis/jarvis_sec/workflow.py +513 -0
- jarvis/jarvis_tools/registry.py +20 -14
- jarvis/jarvis_tools/sub_agent.py +4 -3
- jarvis/jarvis_tools/sub_code_agent.py +3 -3
- jarvis/jarvis_utils/config.py +14 -2
- jarvis/jarvis_utils/methodology.py +25 -19
- jarvis/jarvis_utils/utils.py +193 -2
- {jarvis_ai_assistant-0.4.2.dist-info → jarvis_ai_assistant-0.5.1.dist-info}/METADATA +1 -1
- {jarvis_ai_assistant-0.4.2.dist-info → jarvis_ai_assistant-0.5.1.dist-info}/RECORD +30 -19
- {jarvis_ai_assistant-0.4.2.dist-info → jarvis_ai_assistant-0.5.1.dist-info}/entry_points.txt +2 -0
- {jarvis_ai_assistant-0.4.2.dist-info → jarvis_ai_assistant-0.5.1.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.4.2.dist-info → jarvis_ai_assistant-0.5.1.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.4.2.dist-info → jarvis_ai_assistant-0.5.1.dist-info}/top_level.txt +0 -0
|
@@ -9,9 +9,9 @@ import typer
|
|
|
9
9
|
|
|
10
10
|
from jarvis.jarvis_agent import Agent
|
|
11
11
|
from jarvis.jarvis_code_analysis.checklists.loader import get_language_checklist
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
from jarvis.jarvis_tools.read_code import ReadCodeTool
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
16
16
|
from jarvis.jarvis_utils.tag import ct, ot
|
|
17
17
|
from jarvis.jarvis_utils.utils import init_env, is_context_overflow
|
|
@@ -19,445 +19,398 @@ from jarvis.jarvis_utils.utils import init_env, is_context_overflow
|
|
|
19
19
|
app = typer.Typer(help="自动代码审查工具")
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
22
|
+
def _detect_languages_from_files(file_paths: List[str]) -> List[str]:
|
|
23
|
+
"""
|
|
24
|
+
Detect programming languages from a list of file paths using file extensions.
|
|
25
|
+
Returns a list of detected languages ('c_cpp', 'go', 'python', 'rust', 'java', 'javascript', 'typescript', etc.).
|
|
26
|
+
"""
|
|
27
|
+
if not file_paths:
|
|
28
|
+
return []
|
|
29
|
+
|
|
30
|
+
# Extension-based language detection
|
|
31
|
+
languages = set()
|
|
32
|
+
for file_path in file_paths:
|
|
33
|
+
file_path = file_path.lower()
|
|
34
|
+
_, ext = os.path.splitext(file_path)
|
|
35
|
+
|
|
36
|
+
# Get base name for special files without extensions
|
|
37
|
+
base_name = os.path.basename(file_path)
|
|
38
|
+
|
|
39
|
+
# C/C++
|
|
40
|
+
if ext in [
|
|
41
|
+
".c",
|
|
42
|
+
".cpp",
|
|
43
|
+
".cc",
|
|
44
|
+
".cxx",
|
|
45
|
+
".h",
|
|
46
|
+
".hpp",
|
|
47
|
+
".hxx",
|
|
48
|
+
".inl",
|
|
49
|
+
".ipp",
|
|
50
|
+
]:
|
|
51
|
+
languages.add("c_cpp")
|
|
52
|
+
|
|
53
|
+
# Go
|
|
54
|
+
elif ext in [".go"]:
|
|
55
|
+
languages.add("go")
|
|
56
|
+
|
|
57
|
+
# Python
|
|
58
|
+
elif ext in [".py", ".pyw", ".pyi", ".pyx", ".pxd"] or base_name in [
|
|
59
|
+
"requirements.txt",
|
|
60
|
+
"setup.py",
|
|
61
|
+
"pyproject.toml",
|
|
62
|
+
]:
|
|
63
|
+
languages.add("python")
|
|
64
|
+
|
|
65
|
+
# Rust
|
|
66
|
+
elif ext in [".rs", ".rlib"] or base_name in ["Cargo.toml", "Cargo.lock"]:
|
|
67
|
+
languages.add("rust")
|
|
68
|
+
|
|
69
|
+
# Java
|
|
70
|
+
elif ext in [".java", ".class", ".jar"] or base_name in [
|
|
71
|
+
"pom.xml",
|
|
72
|
+
"build.gradle",
|
|
73
|
+
]:
|
|
74
|
+
languages.add("java")
|
|
75
|
+
|
|
76
|
+
# JavaScript
|
|
77
|
+
elif ext in [".js", ".mjs", ".cjs", ".jsx"]:
|
|
78
|
+
languages.add("javascript")
|
|
79
|
+
|
|
80
|
+
# TypeScript
|
|
81
|
+
elif ext in [".ts", ".tsx", ".cts", ".mts"]:
|
|
82
|
+
languages.add("typescript")
|
|
83
|
+
|
|
84
|
+
# PHP
|
|
85
|
+
elif ext in [".php", ".phtml", ".php5", ".php7", ".phps"]:
|
|
86
|
+
languages.add("php")
|
|
87
|
+
|
|
88
|
+
# Ruby
|
|
89
|
+
elif ext in [".rb", ".rake", ".gemspec"] or base_name in [
|
|
90
|
+
"Gemfile",
|
|
91
|
+
"Rakefile",
|
|
92
|
+
]:
|
|
93
|
+
languages.add("ruby")
|
|
94
|
+
|
|
95
|
+
# Swift
|
|
96
|
+
elif ext in [".swift"]:
|
|
97
|
+
languages.add("swift")
|
|
98
|
+
|
|
99
|
+
# Kotlin
|
|
100
|
+
elif ext in [".kt", ".kts"]:
|
|
101
|
+
languages.add("kotlin")
|
|
102
|
+
|
|
103
|
+
# C#
|
|
104
|
+
elif ext in [".cs", ".csx"]:
|
|
105
|
+
languages.add("csharp")
|
|
106
|
+
|
|
107
|
+
# SQL
|
|
108
|
+
elif ext in [".sql"]:
|
|
109
|
+
languages.add("sql")
|
|
110
|
+
|
|
111
|
+
# Shell/Bash
|
|
112
|
+
elif (
|
|
113
|
+
ext in [".sh", ".bash"]
|
|
114
|
+
or base_name.startswith(".bash")
|
|
115
|
+
or base_name.startswith(".zsh")
|
|
116
|
+
):
|
|
117
|
+
languages.add("shell")
|
|
118
|
+
|
|
119
|
+
# HTML/CSS
|
|
120
|
+
elif ext in [".html", ".htm", ".xhtml"]:
|
|
121
|
+
languages.add("html")
|
|
122
|
+
elif ext in [".css", ".scss", ".sass", ".less"]:
|
|
123
|
+
languages.add("css")
|
|
124
|
+
|
|
125
|
+
# XML/JSON/YAML (config files)
|
|
126
|
+
elif ext in [
|
|
127
|
+
".xml",
|
|
128
|
+
".xsd",
|
|
129
|
+
".dtd",
|
|
130
|
+
".tld",
|
|
131
|
+
".jsp",
|
|
132
|
+
".jspx",
|
|
133
|
+
".tag",
|
|
134
|
+
".tagx",
|
|
135
|
+
]:
|
|
136
|
+
languages.add("xml")
|
|
137
|
+
elif ext in [".json", ".jsonl", ".json5"]:
|
|
138
|
+
languages.add("json")
|
|
139
|
+
elif ext in [".yaml", ".yml"]:
|
|
140
|
+
languages.add("yaml")
|
|
141
|
+
|
|
142
|
+
# Markdown/Documentation
|
|
143
|
+
elif ext in [".md", ".markdown", ".rst", ".adoc"]:
|
|
144
|
+
languages.add("markdown")
|
|
145
|
+
|
|
146
|
+
# Docker
|
|
147
|
+
elif ext in [".dockerfile"] or base_name in [
|
|
148
|
+
"Dockerfile",
|
|
149
|
+
"docker-compose.yml",
|
|
150
|
+
"docker-compose.yaml",
|
|
151
|
+
]:
|
|
152
|
+
languages.add("docker")
|
|
153
|
+
|
|
154
|
+
# Terraform
|
|
155
|
+
elif ext in [".tf", ".tfvars"]:
|
|
156
|
+
languages.add("terraform")
|
|
157
|
+
|
|
158
|
+
# Makefile
|
|
159
|
+
elif ext in [".mk"] or base_name == "Makefile":
|
|
160
|
+
languages.add("makefile")
|
|
161
|
+
|
|
162
|
+
# Map to our primary language groups for checklist purposes
|
|
163
|
+
primary_languages = set()
|
|
164
|
+
language_mapping = {
|
|
165
|
+
"c_cpp": "c_cpp",
|
|
166
|
+
"go": "go",
|
|
167
|
+
"python": "python",
|
|
168
|
+
"rust": "rust",
|
|
169
|
+
"java": "java",
|
|
170
|
+
"javascript": "javascript",
|
|
171
|
+
"typescript": "typescript",
|
|
172
|
+
"php": "php",
|
|
173
|
+
"ruby": "ruby",
|
|
174
|
+
"swift": "swift",
|
|
175
|
+
"kotlin": "kotlin",
|
|
176
|
+
"csharp": "csharp",
|
|
177
|
+
"sql": "sql",
|
|
178
|
+
"shell": "shell",
|
|
179
|
+
"html": "html",
|
|
180
|
+
"css": "css",
|
|
181
|
+
"xml": "xml",
|
|
182
|
+
"json": "json",
|
|
183
|
+
"yaml": "yaml",
|
|
184
|
+
"markdown": "docs",
|
|
185
|
+
"docker": "docker",
|
|
186
|
+
"terraform": "terraform",
|
|
187
|
+
"makefile": "devops",
|
|
58
188
|
}
|
|
59
189
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
# Go
|
|
92
|
-
elif ext in [".go"]:
|
|
93
|
-
languages.add("go")
|
|
94
|
-
|
|
95
|
-
# Python
|
|
96
|
-
elif ext in [".py", ".pyw", ".pyi", ".pyx", ".pxd"] or base_name in [
|
|
97
|
-
"requirements.txt",
|
|
98
|
-
"setup.py",
|
|
99
|
-
"pyproject.toml",
|
|
190
|
+
# Map detected languages to primary language groups
|
|
191
|
+
for lang in languages:
|
|
192
|
+
primary_lang = language_mapping.get(lang)
|
|
193
|
+
if primary_lang:
|
|
194
|
+
# Only keep languages we have checklists for
|
|
195
|
+
if primary_lang in [
|
|
196
|
+
"c_cpp",
|
|
197
|
+
"go",
|
|
198
|
+
"python",
|
|
199
|
+
"rust",
|
|
200
|
+
"java",
|
|
201
|
+
"javascript",
|
|
202
|
+
"typescript",
|
|
203
|
+
"csharp",
|
|
204
|
+
"swift",
|
|
205
|
+
"php",
|
|
206
|
+
"shell",
|
|
207
|
+
"sql",
|
|
208
|
+
"ruby",
|
|
209
|
+
"kotlin",
|
|
210
|
+
"html",
|
|
211
|
+
"css",
|
|
212
|
+
"xml",
|
|
213
|
+
"json",
|
|
214
|
+
"yaml",
|
|
215
|
+
"docker",
|
|
216
|
+
"terraform",
|
|
217
|
+
"docs",
|
|
218
|
+
"markdown",
|
|
219
|
+
"devops",
|
|
220
|
+
"makefile",
|
|
100
221
|
]:
|
|
101
|
-
|
|
222
|
+
primary_languages.add(primary_lang)
|
|
102
223
|
|
|
103
|
-
|
|
104
|
-
elif ext in [".rs", ".rlib"] or base_name in ["Cargo.toml", "Cargo.lock"]:
|
|
105
|
-
languages.add("rust")
|
|
224
|
+
return list(primary_languages)
|
|
106
225
|
|
|
107
|
-
# Java
|
|
108
|
-
elif ext in [".java", ".class", ".jar"] or base_name in [
|
|
109
|
-
"pom.xml",
|
|
110
|
-
"build.gradle",
|
|
111
|
-
]:
|
|
112
|
-
languages.add("java")
|
|
113
226
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
227
|
+
def _get_language_checklist(language: str) -> str:
|
|
228
|
+
"""Get the checklist for a specific language."""
|
|
229
|
+
checklist = get_language_checklist(language)
|
|
230
|
+
return checklist if checklist else ""
|
|
117
231
|
|
|
118
|
-
# TypeScript
|
|
119
|
-
elif ext in [".ts", ".tsx", ".cts", ".mts"]:
|
|
120
|
-
languages.add("typescript")
|
|
121
232
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
233
|
+
def execute_code_review(
|
|
234
|
+
args: Dict[str, Any], agent: Optional["Agent"] = None
|
|
235
|
+
) -> Dict[str, Any]:
|
|
236
|
+
"""
|
|
237
|
+
纯CLI Agent执行入口:根据审查类型获取差异、构建审查上下文并通过Agent生成报告。
|
|
238
|
+
不注册为Tool,不通过ToolRegistry。
|
|
239
|
+
"""
|
|
240
|
+
try:
|
|
241
|
+
review_type = args.get("review_type", "current").strip()
|
|
242
|
+
root_dir = args.get("root_dir", ".")
|
|
125
243
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
"Gemfile",
|
|
129
|
-
"Rakefile",
|
|
130
|
-
]:
|
|
131
|
-
languages.add("ruby")
|
|
132
|
-
|
|
133
|
-
# Swift
|
|
134
|
-
elif ext in [".swift"]:
|
|
135
|
-
languages.add("swift")
|
|
136
|
-
|
|
137
|
-
# Kotlin
|
|
138
|
-
elif ext in [".kt", ".kts"]:
|
|
139
|
-
languages.add("kotlin")
|
|
140
|
-
|
|
141
|
-
# C#
|
|
142
|
-
elif ext in [".cs", ".csx"]:
|
|
143
|
-
languages.add("csharp")
|
|
144
|
-
|
|
145
|
-
# SQL
|
|
146
|
-
elif ext in [".sql"]:
|
|
147
|
-
languages.add("sql")
|
|
148
|
-
|
|
149
|
-
# Shell/Bash
|
|
150
|
-
elif (
|
|
151
|
-
ext in [".sh", ".bash"]
|
|
152
|
-
or base_name.startswith(".bash")
|
|
153
|
-
or base_name.startswith(".zsh")
|
|
154
|
-
):
|
|
155
|
-
languages.add("shell")
|
|
156
|
-
|
|
157
|
-
# HTML/CSS
|
|
158
|
-
elif ext in [".html", ".htm", ".xhtml"]:
|
|
159
|
-
languages.add("html")
|
|
160
|
-
elif ext in [".css", ".scss", ".sass", ".less"]:
|
|
161
|
-
languages.add("css")
|
|
162
|
-
|
|
163
|
-
# XML/JSON/YAML (config files)
|
|
164
|
-
elif ext in [
|
|
165
|
-
".xml",
|
|
166
|
-
".xsd",
|
|
167
|
-
".dtd",
|
|
168
|
-
".tld",
|
|
169
|
-
".jsp",
|
|
170
|
-
".jspx",
|
|
171
|
-
".tag",
|
|
172
|
-
".tagx",
|
|
173
|
-
]:
|
|
174
|
-
languages.add("xml")
|
|
175
|
-
elif ext in [".json", ".jsonl", ".json5"]:
|
|
176
|
-
languages.add("json")
|
|
177
|
-
elif ext in [".yaml", ".yml"]:
|
|
178
|
-
languages.add("yaml")
|
|
179
|
-
|
|
180
|
-
# Markdown/Documentation
|
|
181
|
-
elif ext in [".md", ".markdown", ".rst", ".adoc"]:
|
|
182
|
-
languages.add("markdown")
|
|
183
|
-
|
|
184
|
-
# Docker
|
|
185
|
-
elif ext in [".dockerfile"] or base_name in [
|
|
186
|
-
"Dockerfile",
|
|
187
|
-
"docker-compose.yml",
|
|
188
|
-
"docker-compose.yaml",
|
|
189
|
-
]:
|
|
190
|
-
languages.add("docker")
|
|
191
|
-
|
|
192
|
-
# Terraform
|
|
193
|
-
elif ext in [".tf", ".tfvars"]:
|
|
194
|
-
languages.add("terraform")
|
|
195
|
-
|
|
196
|
-
# Makefile
|
|
197
|
-
elif ext in [".mk"] or base_name == "Makefile":
|
|
198
|
-
languages.add("makefile")
|
|
199
|
-
|
|
200
|
-
# Map to our primary language groups for checklist purposes
|
|
201
|
-
primary_languages = set()
|
|
202
|
-
language_mapping = {
|
|
203
|
-
"c_cpp": "c_cpp",
|
|
204
|
-
"go": "go",
|
|
205
|
-
"python": "python",
|
|
206
|
-
"rust": "rust",
|
|
207
|
-
"java": "java",
|
|
208
|
-
"javascript": "javascript",
|
|
209
|
-
"typescript": "typescript",
|
|
210
|
-
"php": "php",
|
|
211
|
-
"ruby": "ruby",
|
|
212
|
-
"swift": "swift",
|
|
213
|
-
"kotlin": "kotlin",
|
|
214
|
-
"csharp": "csharp",
|
|
215
|
-
"sql": "sql",
|
|
216
|
-
"shell": "shell",
|
|
217
|
-
"html": "html",
|
|
218
|
-
"css": "css",
|
|
219
|
-
"xml": "xml",
|
|
220
|
-
"json": "json",
|
|
221
|
-
"yaml": "yaml",
|
|
222
|
-
"markdown": "docs",
|
|
223
|
-
"docker": "docker",
|
|
224
|
-
"terraform": "terraform",
|
|
225
|
-
"makefile": "devops",
|
|
226
|
-
}
|
|
244
|
+
# Store current directory
|
|
245
|
+
original_dir = os.getcwd()
|
|
227
246
|
|
|
228
|
-
# Map detected languages to primary language groups
|
|
229
|
-
for lang in languages:
|
|
230
|
-
primary_lang = language_mapping.get(lang)
|
|
231
|
-
if primary_lang:
|
|
232
|
-
# Only keep languages we have checklists for
|
|
233
|
-
if primary_lang in [
|
|
234
|
-
"c_cpp",
|
|
235
|
-
"go",
|
|
236
|
-
"python",
|
|
237
|
-
"rust",
|
|
238
|
-
"java",
|
|
239
|
-
"javascript",
|
|
240
|
-
"typescript",
|
|
241
|
-
"csharp",
|
|
242
|
-
"swift",
|
|
243
|
-
"php",
|
|
244
|
-
"shell",
|
|
245
|
-
"sql",
|
|
246
|
-
"ruby",
|
|
247
|
-
"kotlin",
|
|
248
|
-
"html",
|
|
249
|
-
"css",
|
|
250
|
-
"xml",
|
|
251
|
-
"json",
|
|
252
|
-
"yaml",
|
|
253
|
-
"docker",
|
|
254
|
-
"terraform",
|
|
255
|
-
"docs",
|
|
256
|
-
"markdown",
|
|
257
|
-
"devops",
|
|
258
|
-
"makefile",
|
|
259
|
-
]:
|
|
260
|
-
primary_languages.add(primary_lang)
|
|
261
|
-
|
|
262
|
-
return list(primary_languages)
|
|
263
|
-
|
|
264
|
-
def _get_language_checklist(self, language: str) -> str:
|
|
265
|
-
"""Get the checklist for a specific language."""
|
|
266
|
-
checklist = get_language_checklist(language)
|
|
267
|
-
return checklist if checklist else ""
|
|
268
|
-
|
|
269
|
-
def execute(
|
|
270
|
-
self, args: Dict[str, Any], agent: Optional["Agent"] = None
|
|
271
|
-
) -> Dict[str, Any]:
|
|
272
247
|
try:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
#
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
#
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
# Extract changed files using git command
|
|
404
|
-
files_cmd = "git diff --name-only HEAD"
|
|
405
|
-
try:
|
|
406
|
-
files_output = subprocess.check_output(
|
|
407
|
-
files_cmd, shell=True, text=True
|
|
408
|
-
)
|
|
409
|
-
file_paths = [
|
|
410
|
-
f.strip() for f in files_output.split("\n") if f.strip()
|
|
411
|
-
]
|
|
412
|
-
except subprocess.CalledProcessError:
|
|
413
|
-
# Fallback to regex extraction if git command fails
|
|
414
|
-
file_pattern = r"diff --git a/.*?\s+b/(.*?)(\n|$)"
|
|
415
|
-
files = re.findall(file_pattern, diff_output)
|
|
416
|
-
file_paths = [match[0] for match in files]
|
|
417
|
-
|
|
418
|
-
# Detect languages from the file paths
|
|
419
|
-
detected_languages = self._detect_languages_from_files(file_paths)
|
|
420
|
-
|
|
421
|
-
# Add review type and related information to the diff output
|
|
422
|
-
review_info = f"""
|
|
248
|
+
# Change to root_dir
|
|
249
|
+
os.chdir(root_dir)
|
|
250
|
+
|
|
251
|
+
# Variables to store file paths and diff output
|
|
252
|
+
file_paths: List[str] = []
|
|
253
|
+
diff_output = ""
|
|
254
|
+
|
|
255
|
+
# Build git diff command based on review type
|
|
256
|
+
|
|
257
|
+
if review_type == "commit":
|
|
258
|
+
if "commit_sha" not in args:
|
|
259
|
+
return {
|
|
260
|
+
"success": False,
|
|
261
|
+
"stdout": {},
|
|
262
|
+
"stderr": "commit_sha is required for commit review type",
|
|
263
|
+
}
|
|
264
|
+
commit_sha = args["commit_sha"].strip()
|
|
265
|
+
diff_cmd = f"git show {commit_sha} | cat -"
|
|
266
|
+
|
|
267
|
+
# Execute git command and get diff output
|
|
268
|
+
diff_output = subprocess.check_output(
|
|
269
|
+
diff_cmd,
|
|
270
|
+
shell=True,
|
|
271
|
+
text=True,
|
|
272
|
+
encoding="utf-8",
|
|
273
|
+
errors="replace",
|
|
274
|
+
)
|
|
275
|
+
if not diff_output:
|
|
276
|
+
return {
|
|
277
|
+
"success": False,
|
|
278
|
+
"stdout": {},
|
|
279
|
+
"stderr": "No changes to review",
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
# Extract changed files using git command
|
|
283
|
+
files_cmd = f"git show --name-only --pretty=format: {commit_sha}"
|
|
284
|
+
try:
|
|
285
|
+
files_output = subprocess.check_output(files_cmd, shell=True, text=True)
|
|
286
|
+
# Filter out empty lines without using grep
|
|
287
|
+
file_paths = [f.strip() for f in files_output.split("\n") if f.strip()]
|
|
288
|
+
except subprocess.CalledProcessError:
|
|
289
|
+
# Fallback to regex extraction if git command fails
|
|
290
|
+
file_pattern = r"diff --git a/.*?\s+b/(.*?)(\n|$)"
|
|
291
|
+
files = re.findall(file_pattern, diff_output)
|
|
292
|
+
file_paths = [match[0] for match in files]
|
|
293
|
+
|
|
294
|
+
elif review_type == "range":
|
|
295
|
+
if "start_commit" not in args or "end_commit" not in args:
|
|
296
|
+
return {
|
|
297
|
+
"success": False,
|
|
298
|
+
"stdout": {},
|
|
299
|
+
"stderr": "start_commit and end_commit are required for range review type",
|
|
300
|
+
}
|
|
301
|
+
start_commit = args["start_commit"].strip()
|
|
302
|
+
end_commit = args["end_commit"].strip()
|
|
303
|
+
diff_cmd = f"git diff {start_commit}..{end_commit} | cat -"
|
|
304
|
+
|
|
305
|
+
# Execute git command and get diff output
|
|
306
|
+
diff_output = subprocess.check_output(
|
|
307
|
+
diff_cmd,
|
|
308
|
+
shell=True,
|
|
309
|
+
text=True,
|
|
310
|
+
encoding="utf-8",
|
|
311
|
+
errors="replace",
|
|
312
|
+
)
|
|
313
|
+
if not diff_output:
|
|
314
|
+
return {
|
|
315
|
+
"success": False,
|
|
316
|
+
"stdout": {},
|
|
317
|
+
"stderr": "No changes to review",
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
# Extract changed files using git command
|
|
321
|
+
files_cmd = f"git diff --name-only {start_commit}..{end_commit}"
|
|
322
|
+
try:
|
|
323
|
+
files_output = subprocess.check_output(files_cmd, shell=True, text=True)
|
|
324
|
+
file_paths = [f.strip() for f in files_output.split("\n") if f.strip()]
|
|
325
|
+
except subprocess.CalledProcessError:
|
|
326
|
+
# Fallback to regex extraction if git command fails
|
|
327
|
+
file_pattern = r"diff --git a/.*?\s+b/(.*?)(\n|$)"
|
|
328
|
+
files = re.findall(file_pattern, diff_output)
|
|
329
|
+
file_paths = [match[0] for match in files]
|
|
330
|
+
|
|
331
|
+
elif review_type == "file":
|
|
332
|
+
if "file_path" not in args:
|
|
333
|
+
return {
|
|
334
|
+
"success": False,
|
|
335
|
+
"stdout": {},
|
|
336
|
+
"stderr": "file_path is required for file review type",
|
|
337
|
+
}
|
|
338
|
+
file_path = args["file_path"].strip()
|
|
339
|
+
file_paths = [file_path]
|
|
340
|
+
diff_output = ReadCodeTool().execute({"files": [{"path": file_path}]})["stdout"]
|
|
341
|
+
|
|
342
|
+
else: # current changes
|
|
343
|
+
diff_cmd = "git diff HEAD | cat -"
|
|
344
|
+
|
|
345
|
+
# Execute git command and get diff output
|
|
346
|
+
diff_output = subprocess.check_output(
|
|
347
|
+
diff_cmd,
|
|
348
|
+
shell=True,
|
|
349
|
+
text=True,
|
|
350
|
+
encoding="utf-8",
|
|
351
|
+
errors="replace",
|
|
352
|
+
)
|
|
353
|
+
if not diff_output:
|
|
354
|
+
return {
|
|
355
|
+
"success": False,
|
|
356
|
+
"stdout": {},
|
|
357
|
+
"stderr": "No changes to review",
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
# Extract changed files using git command
|
|
361
|
+
files_cmd = "git diff --name-only HEAD"
|
|
362
|
+
try:
|
|
363
|
+
files_output = subprocess.check_output(files_cmd, shell=True, text=True)
|
|
364
|
+
file_paths = [f.strip() for f in files_output.split("\n") if f.strip()]
|
|
365
|
+
except subprocess.CalledProcessError:
|
|
366
|
+
# Fallback to regex extraction if git command fails
|
|
367
|
+
file_pattern = r"diff --git a/.*?\s+b/(.*?)(\n|$)"
|
|
368
|
+
files = re.findall(file_pattern, diff_output)
|
|
369
|
+
file_paths = [match[0] for match in files]
|
|
370
|
+
|
|
371
|
+
# Detect languages from the file paths
|
|
372
|
+
detected_languages = _detect_languages_from_files(file_paths)
|
|
373
|
+
|
|
374
|
+
# Add review type and related information to the diff output
|
|
375
|
+
review_info = f"""
|
|
423
376
|
----- 代码审查信息 -----
|
|
424
377
|
审查类型: {review_type}"""
|
|
425
378
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
379
|
+
# Add specific information based on review type
|
|
380
|
+
if review_type == "commit":
|
|
381
|
+
review_info += f"\n提交SHA: {args['commit_sha']}"
|
|
382
|
+
elif review_type == "range":
|
|
383
|
+
review_info += f"\n起始提交: {args['start_commit']}\n结束提交: {args['end_commit']}"
|
|
384
|
+
elif review_type == "file":
|
|
385
|
+
review_info += f"\n文件路径: {args['file_path']}"
|
|
386
|
+
else: # current changes
|
|
387
|
+
review_info += "\n当前未提交修改"
|
|
388
|
+
|
|
389
|
+
# Add file list
|
|
390
|
+
if file_paths:
|
|
391
|
+
review_info += "\n\n----- 变更文件列表 -----"
|
|
392
|
+
for i, path in enumerate(file_paths, 1):
|
|
393
|
+
review_info += f"\n{i}. {path}"
|
|
394
|
+
|
|
395
|
+
# Add language-specific checklists
|
|
396
|
+
if detected_languages:
|
|
397
|
+
review_info += "\n\n----- 检测到的编程语言 -----"
|
|
398
|
+
review_info += f"\n检测到的语言: {', '.join(detected_languages)}"
|
|
399
|
+
|
|
400
|
+
review_info += "\n\n----- 语言特定审查清单 -----"
|
|
401
|
+
for lang in detected_languages:
|
|
402
|
+
checklist = _get_language_checklist(lang)
|
|
403
|
+
if checklist:
|
|
404
|
+
review_info += f"\n{checklist}"
|
|
405
|
+
|
|
406
|
+
review_info += "\n------------------------\n\n"
|
|
407
|
+
|
|
408
|
+
# Combine review info with diff output
|
|
409
|
+
diff_output = review_info + diff_output
|
|
410
|
+
|
|
411
|
+
PrettyOutput.print(diff_output, OutputType.CODE, lang="diff")
|
|
412
|
+
|
|
413
|
+
system_prompt = """<code_review_guide>
|
|
461
414
|
<role>
|
|
462
415
|
你是一位精益求精的首席代码审查专家,拥有多年企业级代码审计经验。你需要对所有代码变更进行极其全面、严谨且深入的审查,确保代码质量达到最高标准。
|
|
463
416
|
</role>
|
|
@@ -585,47 +538,17 @@ class CodeReviewTool:
|
|
|
585
538
|
|
|
586
539
|
我将分析上传的代码差异文件,进行全面的代码审查。
|
|
587
540
|
</code_review_guide>"""
|
|
588
|
-
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
589
|
-
|
|
590
|
-
tool_registry = ToolRegistry()
|
|
591
|
-
tool_registry.dont_use_tools(["code_review"])
|
|
592
541
|
|
|
593
|
-
|
|
594
|
-
|
|
542
|
+
# Get model_group from args (thinking mode removed)
|
|
543
|
+
model_group = args.get("model_group")
|
|
595
544
|
|
|
596
|
-
# Get platform and model from model_group
|
|
597
|
-
from jarvis.jarvis_utils.config import (
|
|
598
|
-
get_normal_platform_name,
|
|
599
|
-
get_normal_model_name,
|
|
600
|
-
)
|
|
601
545
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
not platform_name
|
|
609
|
-
and calling_agent
|
|
610
|
-
and hasattr(calling_agent, "model")
|
|
611
|
-
and calling_agent.model
|
|
612
|
-
):
|
|
613
|
-
platform_name = calling_agent.model.platform_name()
|
|
614
|
-
model_name = calling_agent.model.name()
|
|
615
|
-
|
|
616
|
-
# Create a new platform instance
|
|
617
|
-
review_model = None
|
|
618
|
-
if platform_name:
|
|
619
|
-
review_model = PlatformRegistry().create_platform(platform_name)
|
|
620
|
-
if review_model and model_name:
|
|
621
|
-
review_model.set_model_name(model_name)
|
|
622
|
-
if model_group:
|
|
623
|
-
review_model.model_group = model_group
|
|
624
|
-
|
|
625
|
-
agent = Agent(
|
|
626
|
-
system_prompt=system_prompt,
|
|
627
|
-
name="Code Review Agent",
|
|
628
|
-
summary_prompt=f"""<code_review_report>
|
|
546
|
+
agent = Agent(
|
|
547
|
+
system_prompt=system_prompt,
|
|
548
|
+
name="Code Review Agent",
|
|
549
|
+
model_group=model_group,
|
|
550
|
+
use_methodology=False,
|
|
551
|
+
summary_prompt=f"""<code_review_report>
|
|
629
552
|
<overview>
|
|
630
553
|
# 整体评估
|
|
631
554
|
[提供对整体代码质量、架构和主要关注点的简明概述,总结主要发现]
|
|
@@ -689,28 +612,26 @@ class CodeReviewTool:
|
|
|
689
612
|
{ot("REPORT")}
|
|
690
613
|
[在此处插入完整MARKDOWN格式的审查报告]
|
|
691
614
|
{ct("REPORT")}""",
|
|
692
|
-
|
|
693
|
-
|
|
615
|
+
auto_complete=args.get("auto_complete", False),
|
|
616
|
+
)
|
|
694
617
|
|
|
695
|
-
|
|
696
|
-
if review_model:
|
|
697
|
-
agent.model = review_model
|
|
618
|
+
# Agent将基于传入的 model_group 自动初始化模型,无需手动注入
|
|
698
619
|
|
|
699
|
-
|
|
700
|
-
|
|
620
|
+
# Determine if we need to split the diff due to size
|
|
621
|
+
max_diff_size = 100 * 1024 * 1024 # Limit to 100MB
|
|
701
622
|
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
623
|
+
if len(diff_output) > max_diff_size:
|
|
624
|
+
PrettyOutput.print(
|
|
625
|
+
f"代码差异内容总大小超过限制 ({len(diff_output)} > {max_diff_size} 字节),将截断内容",
|
|
626
|
+
OutputType.WARNING,
|
|
627
|
+
)
|
|
628
|
+
diff_output = (
|
|
629
|
+
diff_output[:max_diff_size]
|
|
630
|
+
+ "\n\n[diff content truncated due to size limitations...]"
|
|
631
|
+
)
|
|
711
632
|
|
|
712
|
-
|
|
713
|
-
|
|
633
|
+
# Prepare the user prompt for code review
|
|
634
|
+
user_prompt = f"""请对以下代码变更进行全面审查。
|
|
714
635
|
|
|
715
636
|
代码信息:
|
|
716
637
|
- 审查类型: {review_type}
|
|
@@ -719,45 +640,43 @@ class CodeReviewTool:
|
|
|
719
640
|
|
|
720
641
|
请根据SCRIPPPS框架和语言特定的审查清单进行分析,提供详细的代码审查报告。"""
|
|
721
642
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
)
|
|
726
|
-
|
|
727
|
-
temp_file.write(diff_output)
|
|
728
|
-
temp_file.flush()
|
|
643
|
+
# Write the full diff output to a temporary file for uploading
|
|
644
|
+
with tempfile.NamedTemporaryFile(mode="w", suffix=".diff", delete=False) as temp_file:
|
|
645
|
+
temp_file_path = temp_file.name
|
|
646
|
+
temp_file.write(diff_output)
|
|
647
|
+
temp_file.flush()
|
|
729
648
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
649
|
+
try:
|
|
650
|
+
# Check if content is too large
|
|
651
|
+
is_large_content = is_context_overflow(
|
|
652
|
+
diff_output, model_group
|
|
653
|
+
)
|
|
654
|
+
|
|
655
|
+
# Upload the file to the agent's model
|
|
656
|
+
if is_large_content:
|
|
657
|
+
if not agent.model or not agent.model.support_upload_files():
|
|
658
|
+
return {
|
|
659
|
+
"success": False,
|
|
660
|
+
"stdout": "",
|
|
661
|
+
"stderr": "代码差异太大,无法处理",
|
|
662
|
+
}
|
|
735
663
|
|
|
736
|
-
|
|
737
|
-
if
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
"stderr": "上传代码差异文件失败",
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
# Prepare the prompt based on upload status
|
|
756
|
-
if is_large_content:
|
|
757
|
-
# When file is uploaded, reference it in the prompt
|
|
758
|
-
complete_prompt = (
|
|
759
|
-
user_prompt
|
|
760
|
-
+ f"""
|
|
664
|
+
upload_success = agent.model.upload_files([temp_file_path])
|
|
665
|
+
if upload_success:
|
|
666
|
+
pass
|
|
667
|
+
else:
|
|
668
|
+
return {
|
|
669
|
+
"success": False,
|
|
670
|
+
"stdout": "",
|
|
671
|
+
"stderr": "上传代码差异文件失败",
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
# Prepare the prompt based on upload status
|
|
675
|
+
if is_large_content:
|
|
676
|
+
# When file is uploaded, reference it in the prompt
|
|
677
|
+
complete_prompt = (
|
|
678
|
+
user_prompt
|
|
679
|
+
+ f"""
|
|
761
680
|
|
|
762
681
|
我已上传了一个包含代码差异的文件。该文件包含:
|
|
763
682
|
- 审查类型: {review_type}
|
|
@@ -765,39 +684,39 @@ class CodeReviewTool:
|
|
|
765
684
|
- 检测到的编程语言: {', '.join(detected_languages) if detected_languages else '未检测到特定语言'}
|
|
766
685
|
|
|
767
686
|
请基于上传的代码差异文件进行全面审查,并生成详细的代码审查报告。"""
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
finally:
|
|
780
|
-
# Clean up the temporary file
|
|
781
|
-
if os.path.exists(temp_file_path):
|
|
782
|
-
try:
|
|
783
|
-
os.unlink(temp_file_path)
|
|
784
|
-
except Exception:
|
|
785
|
-
PrettyOutput.print(
|
|
786
|
-
f"临时文件 {temp_file_path} 未能删除",
|
|
787
|
-
OutputType.WARNING,
|
|
788
|
-
)
|
|
789
|
-
|
|
790
|
-
return {"success": True, "stdout": result, "stderr": ""}
|
|
687
|
+
)
|
|
688
|
+
# Run the agent with the prompt
|
|
689
|
+
result = agent.run(complete_prompt)
|
|
690
|
+
else:
|
|
691
|
+
complete_prompt = (
|
|
692
|
+
user_prompt
|
|
693
|
+
+ "\n\n代码差异内容:\n```diff\n"
|
|
694
|
+
+ diff_output
|
|
695
|
+
+ "\n```"
|
|
696
|
+
)
|
|
697
|
+
result = agent.run(complete_prompt)
|
|
791
698
|
finally:
|
|
792
|
-
#
|
|
793
|
-
os.
|
|
699
|
+
# Clean up the temporary file
|
|
700
|
+
if os.path.exists(temp_file_path):
|
|
701
|
+
try:
|
|
702
|
+
os.unlink(temp_file_path)
|
|
703
|
+
except Exception:
|
|
704
|
+
PrettyOutput.print(
|
|
705
|
+
f"临时文件 {temp_file_path} 未能删除",
|
|
706
|
+
OutputType.WARNING,
|
|
707
|
+
)
|
|
708
|
+
|
|
709
|
+
return {"success": True, "stdout": result, "stderr": ""}
|
|
710
|
+
finally:
|
|
711
|
+
# Always restore original directory
|
|
712
|
+
os.chdir(original_dir)
|
|
794
713
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
714
|
+
except Exception as e:
|
|
715
|
+
return {
|
|
716
|
+
"success": False,
|
|
717
|
+
"stdout": {},
|
|
718
|
+
"stderr": f"Review failed: {str(e)}",
|
|
719
|
+
}
|
|
801
720
|
|
|
802
721
|
|
|
803
722
|
def extract_code_report(result: str) -> str:
|
|
@@ -811,21 +730,20 @@ def extract_code_report(result: str) -> str:
|
|
|
811
730
|
def review_commit(
|
|
812
731
|
commit: str = typer.Argument(..., help="要审查的提交SHA"),
|
|
813
732
|
root_dir: str = typer.Option(".", "--root-dir", help="代码库根目录路径"),
|
|
814
|
-
|
|
815
733
|
model_group: Optional[str] = typer.Option(
|
|
816
734
|
None, "-g", "--llm-group", help="使用的模型组,覆盖配置文件中的设置"
|
|
817
735
|
),
|
|
736
|
+
auto_complete: bool = typer.Option(False, "--auto-complete/--no-auto-complete", help="是否自动完成"),
|
|
818
737
|
):
|
|
819
738
|
"""审查指定的提交"""
|
|
820
|
-
tool = CodeReviewTool()
|
|
821
739
|
tool_args = {
|
|
822
740
|
"review_type": "commit",
|
|
823
741
|
"commit_sha": commit,
|
|
824
742
|
"root_dir": root_dir,
|
|
825
|
-
|
|
826
743
|
"model_group": model_group,
|
|
744
|
+
"auto_complete": auto_complete,
|
|
827
745
|
}
|
|
828
|
-
result =
|
|
746
|
+
result = execute_code_review(tool_args)
|
|
829
747
|
if result["success"]:
|
|
830
748
|
PrettyOutput.section("自动代码审查结果:", OutputType.SUCCESS)
|
|
831
749
|
report = extract_code_report(result["stdout"])
|
|
@@ -837,20 +755,19 @@ def review_commit(
|
|
|
837
755
|
@app.command("current")
|
|
838
756
|
def review_current(
|
|
839
757
|
root_dir: str = typer.Option(".", "--root-dir", help="代码库根目录路径"),
|
|
840
|
-
|
|
841
758
|
model_group: Optional[str] = typer.Option(
|
|
842
759
|
None, "-g", "--llm-group", help="使用的模型组,覆盖配置文件中的设置"
|
|
843
760
|
),
|
|
761
|
+
auto_complete: bool = typer.Option(False, "--auto-complete/--no-auto-complete", help="是否自动完成"),
|
|
844
762
|
):
|
|
845
763
|
"""审查当前的变更"""
|
|
846
|
-
tool = CodeReviewTool()
|
|
847
764
|
tool_args = {
|
|
848
765
|
"review_type": "current",
|
|
849
766
|
"root_dir": root_dir,
|
|
850
|
-
|
|
851
767
|
"model_group": model_group,
|
|
768
|
+
"auto_complete": auto_complete,
|
|
852
769
|
}
|
|
853
|
-
result =
|
|
770
|
+
result = execute_code_review(tool_args)
|
|
854
771
|
if result["success"]:
|
|
855
772
|
PrettyOutput.section("自动代码审查结果:", OutputType.SUCCESS)
|
|
856
773
|
report = extract_code_report(result["stdout"])
|
|
@@ -864,22 +781,21 @@ def review_range(
|
|
|
864
781
|
start_commit: str = typer.Argument(..., help="起始提交SHA"),
|
|
865
782
|
end_commit: str = typer.Argument(..., help="结束提交SHA"),
|
|
866
783
|
root_dir: str = typer.Option(".", "--root-dir", help="代码库根目录路径"),
|
|
867
|
-
|
|
868
784
|
model_group: Optional[str] = typer.Option(
|
|
869
785
|
None, "-g", "--llm-group", help="使用的模型组,覆盖配置文件中的设置"
|
|
870
786
|
),
|
|
787
|
+
auto_complete: bool = typer.Option(False, "--auto-complete/--no-auto-complete", help="是否自动完成"),
|
|
871
788
|
):
|
|
872
789
|
"""审查提交范围"""
|
|
873
|
-
tool = CodeReviewTool()
|
|
874
790
|
tool_args = {
|
|
875
791
|
"review_type": "range",
|
|
876
792
|
"start_commit": start_commit,
|
|
877
793
|
"end_commit": end_commit,
|
|
878
794
|
"root_dir": root_dir,
|
|
879
|
-
|
|
880
795
|
"model_group": model_group,
|
|
796
|
+
"auto_complete": auto_complete,
|
|
881
797
|
}
|
|
882
|
-
result =
|
|
798
|
+
result = execute_code_review(tool_args)
|
|
883
799
|
if result["success"]:
|
|
884
800
|
PrettyOutput.section("自动代码审查结果:", OutputType.SUCCESS)
|
|
885
801
|
report = extract_code_report(result["stdout"])
|
|
@@ -892,21 +808,20 @@ def review_range(
|
|
|
892
808
|
def review_file(
|
|
893
809
|
file: str = typer.Argument(..., help="要审查的文件路径"),
|
|
894
810
|
root_dir: str = typer.Option(".", "--root-dir", help="代码库根目录路径"),
|
|
895
|
-
|
|
896
811
|
model_group: Optional[str] = typer.Option(
|
|
897
812
|
None, "-g", "--llm-group", help="使用的模型组,覆盖配置文件中的设置"
|
|
898
813
|
),
|
|
814
|
+
auto_complete: bool = typer.Option(False, "--auto-complete/--no-auto-complete", help="是否自动完成"),
|
|
899
815
|
):
|
|
900
816
|
"""审查指定的文件"""
|
|
901
|
-
tool = CodeReviewTool()
|
|
902
817
|
tool_args = {
|
|
903
818
|
"review_type": "file",
|
|
904
819
|
"file_path": file,
|
|
905
820
|
"root_dir": root_dir,
|
|
906
|
-
|
|
907
821
|
"model_group": model_group,
|
|
822
|
+
"auto_complete": auto_complete,
|
|
908
823
|
}
|
|
909
|
-
result =
|
|
824
|
+
result = execute_code_review(tool_args)
|
|
910
825
|
if result["success"]:
|
|
911
826
|
PrettyOutput.section("自动代码审查结果:", OutputType.SUCCESS)
|
|
912
827
|
report = extract_code_report(result["stdout"])
|
|
@@ -927,4 +842,4 @@ def main():
|
|
|
927
842
|
|
|
928
843
|
|
|
929
844
|
if __name__ == "__main__":
|
|
930
|
-
main()
|
|
845
|
+
main()
|