jarvis-ai-assistant 0.1.131__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 +48 -29
- jarvis/jarvis_agent/patch.py +61 -43
- jarvis/jarvis_agent/shell_input_handler.py +1 -1
- jarvis/jarvis_code_agent/code_agent.py +87 -86
- jarvis/jarvis_dev/main.py +335 -626
- jarvis/jarvis_git_squash/main.py +10 -31
- jarvis/jarvis_multi_agent/__init__.py +19 -28
- 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/yuanbao.py +264 -0
- jarvis/jarvis_rag/file_processors.py +138 -0
- jarvis/jarvis_rag/main.py +1305 -425
- jarvis/jarvis_tools/ask_codebase.py +205 -39
- jarvis/jarvis_tools/code_review.py +125 -99
- jarvis/jarvis_tools/execute_python_script.py +58 -0
- jarvis/jarvis_tools/execute_shell.py +13 -26
- jarvis/jarvis_tools/execute_shell_script.py +1 -1
- jarvis/jarvis_tools/file_analyzer.py +271 -0
- jarvis/jarvis_tools/file_operation.py +1 -1
- 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 +4 -4
- jarvis/jarvis_tools/methodology.py +89 -48
- jarvis/jarvis_tools/project_analyzer.py +220 -0
- jarvis/jarvis_tools/read_code.py +23 -2
- jarvis/jarvis_tools/read_webpage.py +195 -81
- jarvis/jarvis_tools/registry.py +132 -11
- jarvis/jarvis_tools/search_web.py +55 -10
- jarvis/jarvis_tools/tool_generator.py +6 -8
- 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 +9 -1
- jarvis/jarvis_utils/input.py +7 -6
- jarvis/jarvis_utils/methodology.py +379 -7
- jarvis/jarvis_utils/output.py +5 -3
- jarvis/jarvis_utils/utils.py +59 -7
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/METADATA +3 -2
- jarvis_ai_assistant-0.1.132.dist-info/RECORD +82 -0
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/entry_points.txt +2 -0
- jarvis/jarvis_codebase/__init__.py +0 -0
- jarvis/jarvis_codebase/main.py +0 -1011
- jarvis/jarvis_tools/treesitter_analyzer.py +0 -331
- jarvis/jarvis_treesitter/README.md +0 -104
- jarvis/jarvis_treesitter/__init__.py +0 -20
- jarvis/jarvis_treesitter/database.py +0 -258
- jarvis/jarvis_treesitter/example.py +0 -115
- jarvis/jarvis_treesitter/grammar_builder.py +0 -182
- jarvis/jarvis_treesitter/language.py +0 -117
- jarvis/jarvis_treesitter/symbol.py +0 -31
- jarvis/jarvis_treesitter/tools_usage.md +0 -121
- jarvis_ai_assistant-0.1.131.dist-info/RECORD +0 -85
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
from typing import Dict, Any, List
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from jarvis.jarvis_agent import Agent
|
|
5
|
+
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
6
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SymbolTool:
|
|
10
|
+
"""
|
|
11
|
+
符号查找工具
|
|
12
|
+
使用agent查找代码库中的符号引用、定义和声明位置
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
name = "find_symbol"
|
|
16
|
+
description = "查找代码符号的引用、定义和声明位置"
|
|
17
|
+
parameters = {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"properties": {
|
|
20
|
+
"symbol": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "要查找的符号名称"
|
|
23
|
+
},
|
|
24
|
+
"root_dir": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "代码库根目录路径(可选)",
|
|
27
|
+
"default": "."
|
|
28
|
+
},
|
|
29
|
+
"file_extensions": {
|
|
30
|
+
"type": "array",
|
|
31
|
+
"items": {
|
|
32
|
+
"type": "string"
|
|
33
|
+
},
|
|
34
|
+
"description": "要搜索的文件扩展名列表(如:['.py', '.js'])(可选)",
|
|
35
|
+
"default": []
|
|
36
|
+
},
|
|
37
|
+
"exclude_dirs": {
|
|
38
|
+
"type": "array",
|
|
39
|
+
"items": {
|
|
40
|
+
"type": "string"
|
|
41
|
+
},
|
|
42
|
+
"description": "要排除的目录列表(可选)",
|
|
43
|
+
"default": []
|
|
44
|
+
},
|
|
45
|
+
"objective": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"description": "描述本次符号查找的目标和用途,例如'了解该符号的使用模式以便重构'",
|
|
48
|
+
"default": ""
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"required": ["symbol"]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
55
|
+
"""
|
|
56
|
+
执行符号查找工具
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
args: 包含参数的字典
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
包含执行结果的字典
|
|
63
|
+
"""
|
|
64
|
+
# 存储原始目录
|
|
65
|
+
original_dir = os.getcwd()
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
# 解析参数
|
|
69
|
+
symbol = args.get("symbol", "")
|
|
70
|
+
root_dir = args.get("root_dir", ".")
|
|
71
|
+
file_extensions = args.get("file_extensions", [])
|
|
72
|
+
exclude_dirs = args.get("exclude_dirs", [])
|
|
73
|
+
objective = args.get("objective", "")
|
|
74
|
+
|
|
75
|
+
# 验证参数
|
|
76
|
+
if not symbol:
|
|
77
|
+
return {
|
|
78
|
+
"success": False,
|
|
79
|
+
"stdout": "",
|
|
80
|
+
"stderr": "必须提供符号名称"
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
# 创建agent的system prompt
|
|
84
|
+
system_prompt = self._create_system_prompt(
|
|
85
|
+
symbol, root_dir, file_extensions, exclude_dirs, objective
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
# 创建agent的summary prompt
|
|
89
|
+
summary_prompt = self._create_summary_prompt(symbol)
|
|
90
|
+
|
|
91
|
+
# 切换到根目录
|
|
92
|
+
os.chdir(root_dir)
|
|
93
|
+
|
|
94
|
+
# 构建使用的工具
|
|
95
|
+
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
96
|
+
tool_registry = ToolRegistry()
|
|
97
|
+
tool_registry.use_tools(["execute_shell", "read_code"])
|
|
98
|
+
|
|
99
|
+
# 创建并运行agent
|
|
100
|
+
symbol_agent = Agent(
|
|
101
|
+
system_prompt=system_prompt,
|
|
102
|
+
name=f"SymbolFinder-{symbol}",
|
|
103
|
+
description=f"查找符号 '{symbol}' 的引用和定义位置",
|
|
104
|
+
summary_prompt=summary_prompt,
|
|
105
|
+
platform=PlatformRegistry().get_codegen_platform(),
|
|
106
|
+
output_handler=[tool_registry],
|
|
107
|
+
need_summary=True,
|
|
108
|
+
is_sub_agent=True,
|
|
109
|
+
use_methodology=False,
|
|
110
|
+
record_methodology=False,
|
|
111
|
+
execute_tool_confirm=False,
|
|
112
|
+
auto_complete=True
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# 运行agent并获取结果
|
|
116
|
+
task_input = f"查找符号 '{symbol}' 在代码库中的引用、定义和声明位置"
|
|
117
|
+
result = symbol_agent.run(task_input)
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
"success": True,
|
|
121
|
+
"stdout": result,
|
|
122
|
+
"stderr": ""
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
except Exception as e:
|
|
126
|
+
PrettyOutput.print(str(e), OutputType.ERROR)
|
|
127
|
+
return {
|
|
128
|
+
"success": False,
|
|
129
|
+
"stdout": "",
|
|
130
|
+
"stderr": f"符号查找失败: {str(e)}"
|
|
131
|
+
}
|
|
132
|
+
finally:
|
|
133
|
+
# 恢复原始目录
|
|
134
|
+
os.chdir(original_dir)
|
|
135
|
+
|
|
136
|
+
def _create_system_prompt(self, symbol: str, root_dir: str,
|
|
137
|
+
file_extensions: List[str], exclude_dirs: List[str],
|
|
138
|
+
objective: str) -> str:
|
|
139
|
+
"""
|
|
140
|
+
创建Agent的system prompt
|
|
141
|
+
|
|
142
|
+
Args:
|
|
143
|
+
symbol: 符号名称
|
|
144
|
+
root_dir: 代码库根目录
|
|
145
|
+
file_extensions: 文件扩展名列表
|
|
146
|
+
exclude_dirs: 排除目录列表
|
|
147
|
+
objective: 分析目标
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
系统提示文本
|
|
151
|
+
"""
|
|
152
|
+
file_ext_str = " ".join([f"*{ext}" for ext in file_extensions]) if file_extensions else ""
|
|
153
|
+
exclude_str = " ".join([f"--glob '!{excl}'" for excl in exclude_dirs]) if exclude_dirs else ""
|
|
154
|
+
objective_text = f"\n\n## 分析目标\n{objective}" if objective else ""
|
|
155
|
+
|
|
156
|
+
return f"""# 代码符号分析专家
|
|
157
|
+
|
|
158
|
+
## 任务描述
|
|
159
|
+
查找符号 `{symbol}` 在代码库中的定义、声明和引用位置,专注于分析目标所需的信息,生成有针对性的符号分析报告。{objective_text}
|
|
160
|
+
|
|
161
|
+
## 工作环境
|
|
162
|
+
- 工作目录: `{root_dir}`
|
|
163
|
+
- 文件类型: {file_ext_str if file_ext_str else "所有文件"}
|
|
164
|
+
- 排除目录: {", ".join(exclude_dirs) if exclude_dirs else "无"}
|
|
165
|
+
|
|
166
|
+
## 分析策略
|
|
167
|
+
1. 首先理解分析目标,明确需要查找的信息类型
|
|
168
|
+
2. 使用适当的搜索模式查找符号定义和引用
|
|
169
|
+
3. 验证搜索结果,确认是目标符号的真正使用
|
|
170
|
+
4. 分析符号上下文,了解其用途和使用方式
|
|
171
|
+
5. 根据分析目标自行确定需要的分析深度和广度
|
|
172
|
+
|
|
173
|
+
## 执行指令
|
|
174
|
+
- 使用ripgrep(rg)或grep工具搜索代码库:
|
|
175
|
+
```
|
|
176
|
+
rg -n "def\\s+{symbol}\\b|class\\s+{symbol}\\b|{symbol}\\s*=" {file_ext_str} {exclude_str}
|
|
177
|
+
rg -n "\\b{symbol}\\b" {file_ext_str} {exclude_str}
|
|
178
|
+
```
|
|
179
|
+
- 使用`read_code`查看上下文确认结果
|
|
180
|
+
|
|
181
|
+
## 输出要求
|
|
182
|
+
- 直接回应分析目标的关键问题
|
|
183
|
+
- 提供与目标相关的符号信息
|
|
184
|
+
- 分析内容应直接服务于分析目标
|
|
185
|
+
- 避免与目标无关的冗余信息
|
|
186
|
+
- 使用具体代码路径和使用示例支持分析结论
|
|
187
|
+
- 提供针对分析目标的具体见解和建议"""
|
|
188
|
+
|
|
189
|
+
def _create_summary_prompt(self, symbol: str) -> str:
|
|
190
|
+
"""
|
|
191
|
+
创建Agent的summary prompt
|
|
192
|
+
|
|
193
|
+
Args:
|
|
194
|
+
symbol: 符号名称
|
|
195
|
+
|
|
196
|
+
Returns:
|
|
197
|
+
总结提示文本
|
|
198
|
+
"""
|
|
199
|
+
return f"""# 符号 `{symbol}` 分析报告
|
|
200
|
+
|
|
201
|
+
## 报告要求
|
|
202
|
+
生成一份完全以分析目标为导向的符号分析报告。不要遵循固定的报告模板,而是完全根据分析目标来组织内容:
|
|
203
|
+
|
|
204
|
+
- 专注回答分析目标提出的问题
|
|
205
|
+
- 只包含与分析目标直接相关的符号发现和洞察
|
|
206
|
+
- 完全跳过与分析目标无关的内容,无需做全面分析
|
|
207
|
+
- 分析深度应与目标的具体需求匹配
|
|
208
|
+
- 使用具体的代码示例支持你的观点
|
|
209
|
+
- 以清晰的Markdown格式呈现,简洁明了
|
|
210
|
+
|
|
211
|
+
在分析中保持灵活性,避免固定思维模式。你的任务不是提供全面的符号概览,而是直接解决分析目标中提出的具体问题。"""
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
from typing import Dict, Any, List
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from jarvis.jarvis_agent import Agent
|
|
5
|
+
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
6
|
+
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FunctionAnalyzerTool:
|
|
10
|
+
"""
|
|
11
|
+
函数分析工具
|
|
12
|
+
使用agent深入分析函数内部实现,包括子函数调用、全局变量使用等
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
name = "function_analyzer"
|
|
16
|
+
description = "深入分析函数内部实现,查找子函数调用、全局变量使用等详细信息"
|
|
17
|
+
parameters = {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"properties": {
|
|
20
|
+
"function_name": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "要分析的函数名称"
|
|
23
|
+
},
|
|
24
|
+
"file_path": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "函数所在文件路径(如果已知)",
|
|
27
|
+
"default": ""
|
|
28
|
+
},
|
|
29
|
+
"root_dir": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "代码库根目录路径(可选)",
|
|
32
|
+
"default": "."
|
|
33
|
+
},
|
|
34
|
+
"file_extensions": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"items": {
|
|
37
|
+
"type": "string"
|
|
38
|
+
},
|
|
39
|
+
"description": "要搜索的文件扩展名列表(如:['.py', '.js'])(可选)",
|
|
40
|
+
"default": []
|
|
41
|
+
},
|
|
42
|
+
"exclude_dirs": {
|
|
43
|
+
"type": "array",
|
|
44
|
+
"items": {
|
|
45
|
+
"type": "string"
|
|
46
|
+
},
|
|
47
|
+
"description": "要排除的目录列表(可选)",
|
|
48
|
+
"default": []
|
|
49
|
+
},
|
|
50
|
+
"analysis_depth": {
|
|
51
|
+
"type": "integer",
|
|
52
|
+
"description": "子函数分析深度(可选),0表示不分析子函数,1表示分析直接子函数,以此类推",
|
|
53
|
+
"default": 1
|
|
54
|
+
},
|
|
55
|
+
"objective": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"description": "描述本次函数分析的目标和用途,例如'理解函数实现以便重构'或'评估性能瓶颈'",
|
|
58
|
+
"default": ""
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"required": ["function_name"]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
65
|
+
"""
|
|
66
|
+
执行函数分析工具
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
args: 包含参数的字典
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
包含执行结果的字典
|
|
73
|
+
"""
|
|
74
|
+
# 存储原始目录
|
|
75
|
+
original_dir = os.getcwd()
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
# 解析参数
|
|
79
|
+
function_name = args.get("function_name", "")
|
|
80
|
+
file_path = args.get("file_path", "")
|
|
81
|
+
root_dir = args.get("root_dir", ".")
|
|
82
|
+
file_extensions = args.get("file_extensions", [])
|
|
83
|
+
exclude_dirs = args.get("exclude_dirs", [])
|
|
84
|
+
analysis_depth = args.get("analysis_depth", 1)
|
|
85
|
+
objective = args.get("objective", "")
|
|
86
|
+
|
|
87
|
+
# 验证参数
|
|
88
|
+
if not function_name:
|
|
89
|
+
return {
|
|
90
|
+
"success": False,
|
|
91
|
+
"stdout": "",
|
|
92
|
+
"stderr": "必须提供函数名称"
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
# 创建agent的system prompt
|
|
96
|
+
system_prompt = self._create_system_prompt(
|
|
97
|
+
function_name, file_path, root_dir,
|
|
98
|
+
file_extensions, exclude_dirs, analysis_depth, objective
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# 创建agent的summary prompt
|
|
102
|
+
summary_prompt = self._create_summary_prompt(function_name, analysis_depth)
|
|
103
|
+
|
|
104
|
+
# 切换到根目录
|
|
105
|
+
os.chdir(root_dir)
|
|
106
|
+
|
|
107
|
+
# 构建使用的工具
|
|
108
|
+
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
109
|
+
tool_registry = ToolRegistry()
|
|
110
|
+
tool_registry.use_tools(["execute_shell", "read_code"])
|
|
111
|
+
|
|
112
|
+
# 创建并运行agent
|
|
113
|
+
analyzer_agent = Agent(
|
|
114
|
+
system_prompt=system_prompt,
|
|
115
|
+
name=f"FunctionAnalyzer-{function_name}",
|
|
116
|
+
description=f"分析 '{function_name}' 函数的内部实现",
|
|
117
|
+
summary_prompt=summary_prompt,
|
|
118
|
+
platform=PlatformRegistry().get_codegen_platform(),
|
|
119
|
+
output_handler=[tool_registry],
|
|
120
|
+
need_summary=True,
|
|
121
|
+
is_sub_agent=True,
|
|
122
|
+
use_methodology=False,
|
|
123
|
+
record_methodology=False,
|
|
124
|
+
execute_tool_confirm=False,
|
|
125
|
+
auto_complete=True
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# 运行agent并获取结果
|
|
129
|
+
task_input = f"深入分析 '{function_name}' 函数的内部实现,包括子函数调用、全局变量使用等详细信息"
|
|
130
|
+
result = analyzer_agent.run(task_input)
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
"success": True,
|
|
134
|
+
"stdout": result,
|
|
135
|
+
"stderr": ""
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
except Exception as e:
|
|
139
|
+
PrettyOutput.print(str(e), OutputType.ERROR)
|
|
140
|
+
return {
|
|
141
|
+
"success": False,
|
|
142
|
+
"stdout": "",
|
|
143
|
+
"stderr": f"函数分析失败: {str(e)}"
|
|
144
|
+
}
|
|
145
|
+
finally:
|
|
146
|
+
# 恢复原始目录
|
|
147
|
+
os.chdir(original_dir)
|
|
148
|
+
|
|
149
|
+
def _create_system_prompt(self, function_name: str, file_path: str, root_dir: str,
|
|
150
|
+
file_extensions: List[str], exclude_dirs: List[str],
|
|
151
|
+
analysis_depth: int, objective: str) -> str:
|
|
152
|
+
"""
|
|
153
|
+
创建Agent的system prompt
|
|
154
|
+
|
|
155
|
+
Args:
|
|
156
|
+
function_name: 函数名称
|
|
157
|
+
file_path: 函数所在文件路径
|
|
158
|
+
root_dir: 代码库根目录
|
|
159
|
+
file_extensions: 文件扩展名列表
|
|
160
|
+
exclude_dirs: 排除目录列表
|
|
161
|
+
analysis_depth: 子函数分析深度
|
|
162
|
+
objective: 分析目标
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
系统提示文本
|
|
166
|
+
"""
|
|
167
|
+
file_ext_str = " ".join([f"*{ext}" for ext in file_extensions]) if file_extensions else ""
|
|
168
|
+
exclude_str = " ".join([f"--glob '!{excl}'" for excl in exclude_dirs]) if exclude_dirs else ""
|
|
169
|
+
|
|
170
|
+
depth_description = "不分析子函数" if analysis_depth == 0 else f"分析 {analysis_depth} 层子函数"
|
|
171
|
+
file_info = f"已知文件路径: {file_path}" if file_path else "需要首先查找函数定义位置"
|
|
172
|
+
objective_text = f"\n\n## 分析目标\n{objective}" if objective else ""
|
|
173
|
+
|
|
174
|
+
return f"""# 函数实现分析专家
|
|
175
|
+
|
|
176
|
+
## 任务描述
|
|
177
|
+
分析函数 `{function_name}` 的实现,专注于分析目标所需的信息,生成有针对性的函数分析报告。{objective_text}
|
|
178
|
+
|
|
179
|
+
## 函数信息
|
|
180
|
+
- 函数名称: `{function_name}`
|
|
181
|
+
- {file_info}
|
|
182
|
+
- 分析深度: {depth_description}
|
|
183
|
+
- 代码范围: {file_ext_str if file_ext_str else "所有文件"}
|
|
184
|
+
- 排除目录: {", ".join(exclude_dirs) if exclude_dirs else "无"}
|
|
185
|
+
|
|
186
|
+
## 分析策略
|
|
187
|
+
1. 首先理解分析目标,明确需要查找的信息
|
|
188
|
+
2. {"在指定文件中定位函数定义" if file_path else "搜索代码库查找函数定义位置"}
|
|
189
|
+
3. 根据分析目标,确定重点分析的方面
|
|
190
|
+
4. 灵活调整分析深度,关注与目标相关的实现细节
|
|
191
|
+
5. 根据目标需要自行判断是否需要分析子函数
|
|
192
|
+
|
|
193
|
+
## 执行指令
|
|
194
|
+
- 查找函数定义:
|
|
195
|
+
```
|
|
196
|
+
rg -n "def\\s+{function_name}\\b" {file_ext_str} {exclude_str}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
- 读取函数实现:
|
|
200
|
+
```
|
|
201
|
+
read_code {{
|
|
202
|
+
"files": [{{
|
|
203
|
+
"path": "{file_path or '找到的文件路径'}",
|
|
204
|
+
"start_line": 函数起始行,
|
|
205
|
+
"end_line": 函数结束行
|
|
206
|
+
}}]
|
|
207
|
+
}}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
- 查找全局变量:
|
|
211
|
+
```
|
|
212
|
+
rg -n "global\\s+\\w+" --include="{file_path or '找到的文件路径'}"
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## 输出要求
|
|
216
|
+
- 直接回应分析目标的关键问题
|
|
217
|
+
- 提供与目标相关的函数实现信息
|
|
218
|
+
- 分析内容应直接服务于分析目标
|
|
219
|
+
- 避免与目标无关的冗余信息
|
|
220
|
+
- 使用具体代码片段和示例支持分析结论
|
|
221
|
+
- 提供针对分析目标的具体见解和建议"""
|
|
222
|
+
|
|
223
|
+
def _create_summary_prompt(self, function_name: str, analysis_depth: int) -> str:
|
|
224
|
+
"""
|
|
225
|
+
创建Agent的summary prompt
|
|
226
|
+
|
|
227
|
+
Args:
|
|
228
|
+
function_name: 函数名称
|
|
229
|
+
analysis_depth: 子函数分析深度
|
|
230
|
+
|
|
231
|
+
Returns:
|
|
232
|
+
总结提示文本
|
|
233
|
+
"""
|
|
234
|
+
depth_description = "不包含子函数分析" if analysis_depth == 0 else f"包含 {analysis_depth} 层子函数分析"
|
|
235
|
+
|
|
236
|
+
return f"""# 函数分析报告: `{function_name}`
|
|
237
|
+
|
|
238
|
+
## 报告要求
|
|
239
|
+
生成一份完全以分析目标为导向的函数分析报告,{depth_description}。不要遵循固定的报告模板,而是完全根据分析目标来组织内容:
|
|
240
|
+
|
|
241
|
+
- 专注回答分析目标提出的问题
|
|
242
|
+
- 只包含与分析目标直接相关的实现发现和洞察
|
|
243
|
+
- 完全跳过与分析目标无关的内容,无需做全面分析
|
|
244
|
+
- 分析深度应与目标的具体需求匹配
|
|
245
|
+
- 使用具体的代码片段支持你的观点
|
|
246
|
+
- 以清晰的Markdown格式呈现,简洁明了
|
|
247
|
+
|
|
248
|
+
在分析中保持灵活性,避免固定思维模式。你的任务不是提供全面的函数概览,而是直接解决分析目标中提出的具体问题。"""
|
|
@@ -12,7 +12,7 @@ import os
|
|
|
12
12
|
|
|
13
13
|
from jarvis.jarvis_utils.git_utils import find_git_root, has_uncommitted_changes
|
|
14
14
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
15
|
-
from jarvis.jarvis_utils.utils import init_env
|
|
15
|
+
from jarvis.jarvis_utils.utils import ct, ot, init_env
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class GitCommitTool:
|
|
@@ -37,7 +37,7 @@ class GitCommitTool:
|
|
|
37
37
|
def _extract_commit_message(self, message):
|
|
38
38
|
"""Raw extraction preserving all characters"""
|
|
39
39
|
r = re.search(
|
|
40
|
-
r"(?i)
|
|
40
|
+
r"(?i)" + ot("COMMIT_MESSAGE") + r"\s*([\s\S]*?)\s*" + ct("COMMIT_MESSAGE"),
|
|
41
41
|
message
|
|
42
42
|
)
|
|
43
43
|
if r:
|
|
@@ -97,10 +97,10 @@ class GitCommitTool:
|
|
|
97
97
|
提交信息应使用{args.get('lang', '中文')}书写
|
|
98
98
|
# 必需结构
|
|
99
99
|
必须使用以下格式:
|
|
100
|
-
|
|
100
|
+
{ot("COMMIT_MESSAGE")}
|
|
101
101
|
<类型>(<范围>): <主题>
|
|
102
102
|
使用祈使语气描述变更内容
|
|
103
|
-
|
|
103
|
+
{ct("COMMIT_MESSAGE")}
|
|
104
104
|
# 格式规则
|
|
105
105
|
1. 类型: fix, feat, docs, style, refactor, test, chore
|
|
106
106
|
2. 范围表示模块 (例如: auth, database)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
|
-
import
|
|
2
|
+
import json
|
|
3
|
+
import glob
|
|
4
|
+
import hashlib
|
|
3
5
|
from typing import Dict, Optional, Any
|
|
4
6
|
|
|
5
7
|
from jarvis.jarvis_utils.config import is_use_methodology
|
|
@@ -35,51 +37,68 @@ class MethodologyTool:
|
|
|
35
37
|
|
|
36
38
|
@staticmethod
|
|
37
39
|
def check()->bool:
|
|
38
|
-
"""
|
|
40
|
+
"""检查是否启用了方法论功能"""
|
|
39
41
|
return is_use_methodology()
|
|
40
42
|
|
|
41
43
|
def __init__(self):
|
|
42
|
-
"""
|
|
43
|
-
self.
|
|
44
|
-
self.
|
|
44
|
+
"""初始化经验管理工具"""
|
|
45
|
+
self.methodology_dir = os.path.expanduser("~/.jarvis/methodologies")
|
|
46
|
+
self._ensure_dir_exists()
|
|
45
47
|
|
|
46
|
-
def
|
|
47
|
-
"""
|
|
48
|
-
if not os.path.exists(self.
|
|
48
|
+
def _ensure_dir_exists(self):
|
|
49
|
+
"""确保方法论目录存在"""
|
|
50
|
+
if not os.path.exists(self.methodology_dir):
|
|
49
51
|
try:
|
|
50
|
-
|
|
51
|
-
yaml.safe_dump({}, f, allow_unicode=True)
|
|
52
|
+
os.makedirs(self.methodology_dir, exist_ok=True)
|
|
52
53
|
except Exception as e:
|
|
53
|
-
PrettyOutput.print(f"
|
|
54
|
-
|
|
55
|
-
def
|
|
56
|
-
"""
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
PrettyOutput.print(f"创建方法论目录失败:{str(e)}", OutputType.ERROR)
|
|
55
|
+
|
|
56
|
+
def _get_methodology_file_path(self, problem_type: str) -> str:
|
|
57
|
+
"""
|
|
58
|
+
根据问题类型获取对应的方法论文件路径
|
|
59
|
+
|
|
60
|
+
参数:
|
|
61
|
+
problem_type: 问题类型
|
|
62
|
+
|
|
63
|
+
返回:
|
|
64
|
+
str: 方法论文件路径
|
|
65
|
+
"""
|
|
66
|
+
# 使用MD5哈希作为文件名,避免文件名中的特殊字符
|
|
67
|
+
safe_filename = hashlib.md5(problem_type.encode('utf-8')).hexdigest()
|
|
68
|
+
return os.path.join(self.methodology_dir, f"{safe_filename}.json")
|
|
63
69
|
|
|
64
|
-
def
|
|
65
|
-
"""
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
def _load_methodologies(self) -> Dict[str, str]:
|
|
71
|
+
"""加载所有方法论"""
|
|
72
|
+
all_methodologies = {}
|
|
73
|
+
|
|
74
|
+
if not os.path.exists(self.methodology_dir):
|
|
75
|
+
return all_methodologies
|
|
76
|
+
|
|
77
|
+
for filepath in glob.glob(os.path.join(self.methodology_dir, "*.json")):
|
|
78
|
+
try:
|
|
79
|
+
with open(filepath, "r", encoding="utf-8", errors="ignore") as f:
|
|
80
|
+
methodology = json.load(f)
|
|
81
|
+
problem_type = methodology.get("problem_type", "")
|
|
82
|
+
content = methodology.get("content", "")
|
|
83
|
+
if problem_type and content:
|
|
84
|
+
all_methodologies[problem_type] = content
|
|
85
|
+
except Exception as e:
|
|
86
|
+
filename = os.path.basename(filepath)
|
|
87
|
+
PrettyOutput.print(f"加载方法论文件 {filename} 失败: {str(e)}", OutputType.WARNING)
|
|
88
|
+
|
|
89
|
+
return all_methodologies
|
|
71
90
|
|
|
72
91
|
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
73
|
-
"""
|
|
92
|
+
"""执行管理方法论的操作
|
|
74
93
|
|
|
75
94
|
Args:
|
|
76
|
-
args:
|
|
77
|
-
- operation:
|
|
78
|
-
- problem_type:
|
|
79
|
-
- content:
|
|
95
|
+
args: 包含操作参数的字典
|
|
96
|
+
- operation: 操作类型 (delete/update/add)
|
|
97
|
+
- problem_type: 问题类型
|
|
98
|
+
- content: 方法论内容 (更新和添加时必填)
|
|
80
99
|
|
|
81
100
|
Returns:
|
|
82
|
-
Dict[str, Any]:
|
|
101
|
+
Dict[str, Any]: 包含执行结果的字典
|
|
83
102
|
"""
|
|
84
103
|
operation = args.get("operation", "").strip()
|
|
85
104
|
problem_type = args.get("problem_type", "").strip()
|
|
@@ -92,16 +111,18 @@ class MethodologyTool:
|
|
|
92
111
|
"stderr": "Missing required parameters: operation and problem_type"
|
|
93
112
|
}
|
|
94
113
|
|
|
95
|
-
methodologies = self._load_methodologies()
|
|
96
|
-
|
|
97
114
|
try:
|
|
98
115
|
if operation == "delete":
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
116
|
+
# 获取方法论文件路径
|
|
117
|
+
file_path = self._get_methodology_file_path(problem_type)
|
|
118
|
+
|
|
119
|
+
# 检查文件是否存在
|
|
120
|
+
if os.path.exists(file_path):
|
|
121
|
+
os.remove(file_path)
|
|
102
122
|
return {
|
|
103
123
|
"success": True,
|
|
104
|
-
"stdout": f"Deleted methodology for problem type '{problem_type}'"
|
|
124
|
+
"stdout": f"Deleted methodology for problem type '{problem_type}'",
|
|
125
|
+
"stderr": ""
|
|
105
126
|
}
|
|
106
127
|
else:
|
|
107
128
|
return {
|
|
@@ -117,11 +138,21 @@ class MethodologyTool:
|
|
|
117
138
|
"stdout": "",
|
|
118
139
|
"stderr": "Need to provide methodology content"
|
|
119
140
|
}
|
|
120
|
-
|
|
121
|
-
methodologies[problem_type] = content
|
|
122
|
-
self._save_methodologies(methodologies)
|
|
123
141
|
|
|
124
|
-
|
|
142
|
+
# 确保目录存在
|
|
143
|
+
self._ensure_dir_exists()
|
|
144
|
+
|
|
145
|
+
# 获取方法论文件路径
|
|
146
|
+
file_path = self._get_methodology_file_path(problem_type)
|
|
147
|
+
|
|
148
|
+
# 保存方法论到单独的文件
|
|
149
|
+
with open(file_path, "w", encoding="utf-8", errors="ignore") as f:
|
|
150
|
+
json.dump({
|
|
151
|
+
"problem_type": problem_type,
|
|
152
|
+
"content": content
|
|
153
|
+
}, f, ensure_ascii=False, indent=2)
|
|
154
|
+
|
|
155
|
+
action = "Updated" if os.path.exists(file_path) else "Added"
|
|
125
156
|
return {
|
|
126
157
|
"success": True,
|
|
127
158
|
"stdout": f"{action} methodology for problem type '{problem_type}'",
|
|
@@ -143,13 +174,23 @@ class MethodologyTool:
|
|
|
143
174
|
}
|
|
144
175
|
|
|
145
176
|
def get_methodology(self, problem_type: str) -> Optional[str]:
|
|
146
|
-
"""
|
|
177
|
+
"""获取特定问题类型的方法论
|
|
147
178
|
|
|
148
179
|
Args:
|
|
149
|
-
problem_type:
|
|
180
|
+
problem_type: 问题类型
|
|
150
181
|
|
|
151
182
|
Returns:
|
|
152
|
-
Optional[str]:
|
|
183
|
+
Optional[str]: 方法论内容,如果不存在则返回 None
|
|
153
184
|
"""
|
|
154
|
-
|
|
155
|
-
|
|
185
|
+
file_path = self._get_methodology_file_path(problem_type)
|
|
186
|
+
|
|
187
|
+
if not os.path.exists(file_path):
|
|
188
|
+
return None
|
|
189
|
+
|
|
190
|
+
try:
|
|
191
|
+
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
192
|
+
methodology = json.load(f)
|
|
193
|
+
return methodology.get("content")
|
|
194
|
+
except Exception as e:
|
|
195
|
+
PrettyOutput.print(f"读取方法论失败: {str(e)}", OutputType.ERROR)
|
|
196
|
+
return None
|