jarvis-ai-assistant 0.1.130__py3-none-any.whl → 0.1.132__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 +71 -38
- jarvis/jarvis_agent/builtin_input_handler.py +73 -0
- jarvis/{jarvis_code_agent → jarvis_agent}/file_input_handler.py +1 -1
- jarvis/jarvis_agent/main.py +1 -1
- jarvis/{jarvis_code_agent → jarvis_agent}/patch.py +77 -55
- jarvis/{jarvis_code_agent → jarvis_agent}/shell_input_handler.py +1 -2
- jarvis/jarvis_code_agent/code_agent.py +93 -88
- jarvis/jarvis_dev/main.py +335 -626
- jarvis/jarvis_git_squash/main.py +11 -32
- jarvis/jarvis_lsp/base.py +2 -26
- jarvis/jarvis_lsp/cpp.py +2 -14
- jarvis/jarvis_lsp/go.py +0 -13
- jarvis/jarvis_lsp/python.py +1 -30
- jarvis/jarvis_lsp/registry.py +10 -14
- jarvis/jarvis_lsp/rust.py +0 -12
- jarvis/jarvis_multi_agent/__init__.py +20 -29
- jarvis/jarvis_platform/ai8.py +7 -32
- jarvis/jarvis_platform/base.py +2 -7
- jarvis/jarvis_platform/kimi.py +3 -144
- jarvis/jarvis_platform/ollama.py +54 -68
- jarvis/jarvis_platform/openai.py +0 -4
- jarvis/jarvis_platform/oyi.py +0 -75
- jarvis/jarvis_platform/registry.py +1 -1
- jarvis/jarvis_platform/yuanbao.py +264 -0
- jarvis/jarvis_platform_manager/main.py +3 -3
- jarvis/jarvis_rag/file_processors.py +138 -0
- jarvis/jarvis_rag/main.py +1305 -425
- jarvis/jarvis_tools/ask_codebase.py +227 -41
- jarvis/jarvis_tools/code_review.py +229 -166
- jarvis/jarvis_tools/create_code_agent.py +76 -72
- jarvis/jarvis_tools/create_sub_agent.py +32 -15
- jarvis/jarvis_tools/execute_python_script.py +58 -0
- jarvis/jarvis_tools/execute_shell.py +15 -28
- jarvis/jarvis_tools/execute_shell_script.py +2 -2
- jarvis/jarvis_tools/file_analyzer.py +271 -0
- jarvis/jarvis_tools/file_operation.py +3 -3
- jarvis/jarvis_tools/find_caller.py +213 -0
- jarvis/jarvis_tools/find_symbol.py +211 -0
- jarvis/jarvis_tools/function_analyzer.py +248 -0
- jarvis/jarvis_tools/git_commiter.py +89 -70
- jarvis/jarvis_tools/lsp_find_definition.py +83 -67
- jarvis/jarvis_tools/lsp_find_references.py +62 -46
- jarvis/jarvis_tools/lsp_get_diagnostics.py +90 -74
- jarvis/jarvis_tools/methodology.py +89 -48
- jarvis/jarvis_tools/project_analyzer.py +220 -0
- jarvis/jarvis_tools/read_code.py +24 -3
- jarvis/jarvis_tools/read_webpage.py +195 -81
- jarvis/jarvis_tools/registry.py +132 -11
- jarvis/jarvis_tools/search_web.py +73 -30
- jarvis/jarvis_tools/tool_generator.py +7 -9
- jarvis/jarvis_utils/__init__.py +1 -0
- jarvis/jarvis_utils/config.py +67 -3
- jarvis/jarvis_utils/embedding.py +344 -45
- jarvis/jarvis_utils/git_utils.py +18 -2
- jarvis/jarvis_utils/input.py +7 -4
- jarvis/jarvis_utils/methodology.py +379 -7
- jarvis/jarvis_utils/output.py +5 -3
- jarvis/jarvis_utils/utils.py +62 -10
- {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/METADATA +3 -4
- jarvis_ai_assistant-0.1.132.dist-info/RECORD +82 -0
- {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/entry_points.txt +2 -0
- jarvis/jarvis_c2rust/c2rust.yaml +0 -734
- jarvis/jarvis_code_agent/builtin_input_handler.py +0 -43
- jarvis/jarvis_codebase/__init__.py +0 -0
- jarvis/jarvis_codebase/main.py +0 -1011
- jarvis/jarvis_tools/lsp_get_document_symbols.py +0 -87
- jarvis/jarvis_tools/lsp_prepare_rename.py +0 -130
- jarvis_ai_assistant-0.1.130.dist-info/RECORD +0 -79
- {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.130.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/top_level.txt +0 -0
|
@@ -1,27 +1,43 @@
|
|
|
1
1
|
from typing import Dict, Any
|
|
2
|
+
import os
|
|
3
|
+
import pathlib
|
|
2
4
|
|
|
3
|
-
from
|
|
4
|
-
|
|
5
|
-
from jarvis.
|
|
6
|
-
from jarvis.
|
|
5
|
+
from colorama import init
|
|
6
|
+
|
|
7
|
+
from jarvis.jarvis_agent import Agent
|
|
8
|
+
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
7
9
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
10
|
+
from jarvis.jarvis_utils.git_utils import find_git_root
|
|
11
|
+
from jarvis.jarvis_utils.config import dont_use_local_model
|
|
12
|
+
from jarvis.jarvis_utils.utils import init_env
|
|
8
13
|
|
|
9
14
|
class AskCodebaseTool:
|
|
10
|
-
"""用于智能代码库查询和分析的工具
|
|
15
|
+
"""用于智能代码库查询和分析的工具
|
|
16
|
+
|
|
17
|
+
适用场景:
|
|
18
|
+
- 查询特定功能所在的文件位置
|
|
19
|
+
- 了解单个功能点的实现原理
|
|
20
|
+
- 查找特定API或接口的用法
|
|
21
|
+
|
|
22
|
+
不适用场景:
|
|
23
|
+
- 跨越多文件的大范围分析
|
|
24
|
+
- 复杂系统架构的全面评估
|
|
25
|
+
- 需要深入上下文理解的代码重构
|
|
26
|
+
"""
|
|
11
27
|
|
|
12
28
|
name = "ask_codebase"
|
|
13
|
-
description = "
|
|
29
|
+
description = "查询代码库中特定功能的位置和实现原理,适合定位功能所在文件和理解单点实现,不适合跨文件大范围分析"
|
|
14
30
|
parameters = {
|
|
15
31
|
"type": "object",
|
|
16
32
|
"properties": {
|
|
17
33
|
"question": {
|
|
18
34
|
"type": "string",
|
|
19
|
-
"description": "
|
|
35
|
+
"description": "关于代码库的问题,例如'登录功能在哪个文件实现?'或'如何实现了JWT验证?'"
|
|
20
36
|
},
|
|
21
|
-
"
|
|
22
|
-
"type": "
|
|
23
|
-
"description": "
|
|
24
|
-
"default":
|
|
37
|
+
"root_dir": {
|
|
38
|
+
"type": "string",
|
|
39
|
+
"description": "代码库根目录路径(可选)",
|
|
40
|
+
"default": "."
|
|
25
41
|
}
|
|
26
42
|
},
|
|
27
43
|
"required": ["question"]
|
|
@@ -32,43 +48,78 @@ class AskCodebaseTool:
|
|
|
32
48
|
return not dont_use_local_model()
|
|
33
49
|
|
|
34
50
|
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
35
|
-
"""Execute codebase analysis using
|
|
51
|
+
"""Execute codebase analysis using an Agent with execute_shell and rag tools
|
|
36
52
|
|
|
37
53
|
Args:
|
|
38
54
|
args: Dictionary containing:
|
|
39
|
-
- question: The question to answer
|
|
55
|
+
- question: The question to answer, preferably about locating functionality
|
|
56
|
+
or understanding implementation details of a specific feature
|
|
40
57
|
- top_k: Optional number of files to analyze
|
|
58
|
+
- root_dir: Optional root directory of the codebase
|
|
41
59
|
|
|
42
60
|
Returns:
|
|
43
61
|
Dict containing:
|
|
44
62
|
- success: Boolean indicating success
|
|
45
63
|
- stdout: Analysis result
|
|
46
64
|
- stderr: Error message if any
|
|
65
|
+
|
|
66
|
+
Note:
|
|
67
|
+
This tool works best for focused questions about specific features or implementations.
|
|
68
|
+
It is not designed for comprehensive multi-file analysis or complex architectural questions.
|
|
47
69
|
"""
|
|
48
70
|
try:
|
|
49
71
|
question = args["question"]
|
|
50
|
-
|
|
51
|
-
# Create new CodeBase instance
|
|
52
|
-
git_root = find_git_root()
|
|
53
|
-
codebase = CodeBase(git_root)
|
|
54
|
-
|
|
55
|
-
# Use ask_codebase method
|
|
56
|
-
|
|
57
|
-
files, response = codebase.ask_codebase(question, top_k)
|
|
58
|
-
|
|
72
|
+
root_dir = args.get("root_dir", ".")
|
|
59
73
|
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
output = "找到的相关文件:\n"
|
|
63
|
-
for file in files:
|
|
64
|
-
output += f"- {file['file']} ({file['reason']})\n"
|
|
65
|
-
PrettyOutput.print(output, OutputType.INFO, lang="markdown")
|
|
74
|
+
# Store current directory
|
|
75
|
+
original_dir = os.getcwd()
|
|
66
76
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
try:
|
|
78
|
+
# Change to root_dir
|
|
79
|
+
os.chdir(root_dir)
|
|
80
|
+
|
|
81
|
+
# Get git root directory
|
|
82
|
+
git_root = find_git_root() or os.getcwd()
|
|
83
|
+
|
|
84
|
+
# Create system prompt for the Agent
|
|
85
|
+
system_prompt = self._create_system_prompt(question, git_root)
|
|
86
|
+
|
|
87
|
+
# Create summary prompt for the Agent
|
|
88
|
+
summary_prompt = self._create_summary_prompt(question)
|
|
89
|
+
|
|
90
|
+
# Create tools registry
|
|
91
|
+
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
92
|
+
tool_registry = ToolRegistry()
|
|
93
|
+
tool_registry.use_tools(["execute_shell", "read_code", "rag"])
|
|
94
|
+
|
|
95
|
+
# Create and run Agent
|
|
96
|
+
analyzer_agent = Agent(
|
|
97
|
+
system_prompt=system_prompt,
|
|
98
|
+
name=f"CodebaseAnalyzer",
|
|
99
|
+
description=f"分析代码库中的功能实现和定位",
|
|
100
|
+
summary_prompt=summary_prompt,
|
|
101
|
+
platform=PlatformRegistry().get_codegen_platform(),
|
|
102
|
+
output_handler=[tool_registry],
|
|
103
|
+
need_summary=True,
|
|
104
|
+
is_sub_agent=True,
|
|
105
|
+
use_methodology=False,
|
|
106
|
+
record_methodology=False,
|
|
107
|
+
execute_tool_confirm=False,
|
|
108
|
+
auto_complete=True
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# Run agent and get result
|
|
112
|
+
task_input = f"回答关于代码库的问题: {question}"
|
|
113
|
+
result = analyzer_agent.run(task_input)
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
"success": True,
|
|
117
|
+
"stdout": result,
|
|
118
|
+
"stderr": ""
|
|
119
|
+
}
|
|
120
|
+
finally:
|
|
121
|
+
# Always restore original directory
|
|
122
|
+
os.chdir(original_dir)
|
|
72
123
|
except Exception as e:
|
|
73
124
|
error_msg = f"分析代码库失败: {str(e)}"
|
|
74
125
|
PrettyOutput.print(error_msg, OutputType.WARNING)
|
|
@@ -77,26 +128,161 @@ class AskCodebaseTool:
|
|
|
77
128
|
"stdout": "",
|
|
78
129
|
"stderr": error_msg
|
|
79
130
|
}
|
|
131
|
+
|
|
132
|
+
def _create_system_prompt(self, question: str, git_root: str) -> str:
|
|
133
|
+
"""创建Agent的system prompt
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
question: 用户问题
|
|
137
|
+
git_root: Git仓库根目录
|
|
138
|
+
|
|
139
|
+
Returns:
|
|
140
|
+
系统提示文本
|
|
141
|
+
"""
|
|
142
|
+
return f"""# 代码库分析专家
|
|
143
|
+
|
|
144
|
+
## 任务描述
|
|
145
|
+
分析代码库,找出与用户问题最相关的信息,提供准确、具体的回答。
|
|
146
|
+
|
|
147
|
+
## 问题信息
|
|
148
|
+
- 问题: {question}
|
|
149
|
+
- 代码库根目录: {git_root}
|
|
150
|
+
|
|
151
|
+
## 工具使用优先级
|
|
152
|
+
1. **优先使用 execute_shell**: 首先使用shell命令查找和分析相关文件
|
|
153
|
+
2. **优先使用 read_code**: 找到相关文件后优先使用read_code读取文件内容
|
|
154
|
+
3. **谨慎使用 rag**: 仅在shell命令和直接文件读取无法解决问题时作为辅助手段
|
|
155
|
+
|
|
156
|
+
## 分析策略
|
|
157
|
+
1. 首先理解问题,确定需要查找的关键信息和代码组件
|
|
158
|
+
2. 使用shell命令(execute_shell)搜索和查找可能相关的文件
|
|
159
|
+
3. 使用read_code工具直接读取和分析相关文件内容
|
|
160
|
+
4. 只有在必要时才使用RAG工具作为辅助手段
|
|
161
|
+
5. 根据文件内容提供具体、准确的回答
|
|
162
|
+
|
|
163
|
+
## 分析步骤
|
|
164
|
+
1. **探索代码库结构**:
|
|
165
|
+
- 使用shell命令了解目录结构,找出可能包含相关功能的位置
|
|
166
|
+
- 识别主要模块和组件
|
|
167
|
+
|
|
168
|
+
2. **定位相关文件**:
|
|
169
|
+
- 优先使用grep、find等shell命令查找关键词
|
|
170
|
+
- 使用文件名、关键词搜索找到潜在相关文件
|
|
171
|
+
|
|
172
|
+
3. **深入分析代码**:
|
|
173
|
+
- 使用read_code工具直接读取文件内容
|
|
174
|
+
- 分析关键文件的实现细节
|
|
175
|
+
- 识别功能的实现方式和关键逻辑
|
|
176
|
+
|
|
177
|
+
4. **回答问题**:
|
|
178
|
+
- 提供基于直接分析代码的具体回答
|
|
179
|
+
- 引用具体文件和代码片段作为依据
|
|
180
|
+
|
|
181
|
+
## 关于RAG工具使用
|
|
182
|
+
- RAG工具应作为最后选择,仅在shell命令和直接文件读取无法解决问题时使用
|
|
183
|
+
- RAG工具返回的信息可能存在偏差或不准确之处
|
|
184
|
+
- 必须通过查看实际代码文件验证RAG返回的每条重要信息
|
|
185
|
+
- 对于关键发现,始终使用`read_code`工具查看原始文件内容进行求证
|
|
186
|
+
- 如发现RAG结果与实际代码不符,以实际代码为准
|
|
187
|
+
|
|
188
|
+
## 探索命令示例
|
|
189
|
+
```bash
|
|
190
|
+
# 查看目录结构
|
|
191
|
+
find . -type d -not -path "*/\\.*" | sort
|
|
192
|
+
|
|
193
|
+
# 搜索与问题相关的文件
|
|
194
|
+
find . -type f -name "*.py" -o -name "*.js" | xargs grep -l "关键词"
|
|
195
|
+
grep -r "关键词" --include="*.py" .
|
|
196
|
+
|
|
197
|
+
# 查看文件内容
|
|
198
|
+
cat 文件路径
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
## 输出要求
|
|
203
|
+
- 提供准确、具体的回答,避免模糊不清的描述
|
|
204
|
+
- 引用具体文件路径和代码片段作为依据
|
|
205
|
+
- 如果无法找到答案,明确说明并提供原因
|
|
206
|
+
- 组织信息的逻辑清晰,便于理解
|
|
207
|
+
- 对复杂概念提供简明解释
|
|
208
|
+
- 明确区分已验证的信息和待验证的信息"""
|
|
209
|
+
|
|
210
|
+
def _create_summary_prompt(self, question: str) -> str:
|
|
211
|
+
"""创建Agent的summary prompt
|
|
212
|
+
|
|
213
|
+
Args:
|
|
214
|
+
question: 用户问题
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
总结提示文本
|
|
218
|
+
"""
|
|
219
|
+
return f"""# 代码库分析报告
|
|
220
|
+
|
|
221
|
+
## 报告要求
|
|
222
|
+
生成关于以下问题的清晰、准确的分析报告:
|
|
223
|
+
|
|
224
|
+
**问题**: {question}
|
|
225
|
+
|
|
226
|
+
报告应包含:
|
|
227
|
+
|
|
228
|
+
1. **问题回答**:
|
|
229
|
+
- 直接、具体地回答问题
|
|
230
|
+
- 基于代码库中的实际代码
|
|
231
|
+
- 避免模糊或推测性的回答
|
|
232
|
+
|
|
233
|
+
2. **核心发现**:
|
|
234
|
+
- 相关文件和代码位置
|
|
235
|
+
- 关键实现细节
|
|
236
|
+
- 功能运作机制
|
|
237
|
+
|
|
238
|
+
3. **证据引用**:
|
|
239
|
+
- 引用具体文件路径
|
|
240
|
+
- 包含关键代码片段
|
|
241
|
+
- 解释代码如何支持你的回答
|
|
242
|
+
|
|
243
|
+
4. **局限性**(如有):
|
|
244
|
+
- 指出分析的任何局限
|
|
245
|
+
- 说明任何无法确定的信息
|
|
246
|
+
|
|
247
|
+
使用清晰的Markdown格式,重点突出对问题的回答和支持证据。"""
|
|
248
|
+
|
|
249
|
+
|
|
80
250
|
def main():
|
|
81
|
-
"""
|
|
251
|
+
"""
|
|
252
|
+
命令行入口点,允许将ask_codebase作为独立脚本运行
|
|
253
|
+
|
|
254
|
+
用法示例:
|
|
255
|
+
```
|
|
256
|
+
python -m jarvis.jarvis_tools.ask_codebase "登录功能在哪个文件实现?" --root_dir /path/to/codebase
|
|
257
|
+
```
|
|
258
|
+
"""
|
|
82
259
|
import argparse
|
|
260
|
+
import sys
|
|
261
|
+
|
|
262
|
+
init_env()
|
|
83
263
|
|
|
84
|
-
|
|
85
|
-
parser.
|
|
86
|
-
parser.add_argument(
|
|
264
|
+
# 创建命令行参数解析器
|
|
265
|
+
parser = argparse.ArgumentParser(description="智能代码库查询工具")
|
|
266
|
+
parser.add_argument("question", help="关于代码库的问题")
|
|
267
|
+
parser.add_argument("--root_dir", "-d", default=".", help="代码库根目录路径")
|
|
87
268
|
|
|
269
|
+
# 解析命令行参数
|
|
88
270
|
args = parser.parse_args()
|
|
271
|
+
|
|
272
|
+
# 创建并执行工具
|
|
89
273
|
tool = AskCodebaseTool()
|
|
90
274
|
result = tool.execute({
|
|
91
275
|
"question": args.question,
|
|
92
|
-
"
|
|
276
|
+
"root_dir": args.root_dir
|
|
93
277
|
})
|
|
94
278
|
|
|
279
|
+
# 输出结果
|
|
95
280
|
if result["success"]:
|
|
96
|
-
PrettyOutput.print(result["stdout"], OutputType.
|
|
281
|
+
PrettyOutput.print(result["stdout"], OutputType.SUCCESS)
|
|
97
282
|
else:
|
|
98
283
|
PrettyOutput.print(result["stderr"], OutputType.WARNING)
|
|
99
|
-
|
|
284
|
+
sys.exit(1)
|
|
285
|
+
|
|
100
286
|
|
|
101
287
|
if __name__ == "__main__":
|
|
102
|
-
main()
|
|
288
|
+
main()
|