jarvis-ai-assistant 0.1.131__py3-none-any.whl → 0.1.134__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.
Potentially problematic release.
This version of jarvis-ai-assistant might be problematic. Click here for more details.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +165 -285
- jarvis/jarvis_agent/jarvis.py +143 -0
- jarvis/jarvis_agent/main.py +0 -2
- jarvis/jarvis_agent/patch.py +70 -48
- jarvis/jarvis_agent/shell_input_handler.py +1 -1
- jarvis/jarvis_code_agent/code_agent.py +169 -117
- jarvis/jarvis_dev/main.py +327 -626
- jarvis/jarvis_git_squash/main.py +10 -31
- jarvis/jarvis_lsp/base.py +0 -42
- jarvis/jarvis_lsp/cpp.py +0 -15
- jarvis/jarvis_lsp/go.py +0 -15
- jarvis/jarvis_lsp/python.py +0 -19
- jarvis/jarvis_lsp/registry.py +0 -62
- jarvis/jarvis_lsp/rust.py +0 -15
- jarvis/jarvis_multi_agent/__init__.py +19 -69
- jarvis/jarvis_multi_agent/main.py +43 -0
- 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 +2 -16
- 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 +216 -43
- jarvis/jarvis_tools/code_review.py +158 -113
- jarvis/jarvis_tools/create_sub_agent.py +0 -1
- 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 +282 -0
- jarvis/jarvis_tools/file_operation.py +1 -1
- jarvis/jarvis_tools/find_caller.py +278 -0
- jarvis/jarvis_tools/find_symbol.py +295 -0
- jarvis/jarvis_tools/function_analyzer.py +331 -0
- jarvis/jarvis_tools/git_commiter.py +5 -5
- jarvis/jarvis_tools/methodology.py +88 -53
- jarvis/jarvis_tools/project_analyzer.py +308 -0
- jarvis/jarvis_tools/rag.py +0 -5
- 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 +22 -307
- jarvis/jarvis_tools/tool_generator.py +8 -10
- jarvis/jarvis_utils/__init__.py +1 -0
- jarvis/jarvis_utils/config.py +80 -76
- 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 +384 -15
- jarvis/jarvis_utils/output.py +5 -3
- jarvis/jarvis_utils/utils.py +60 -8
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/METADATA +8 -16
- jarvis_ai_assistant-0.1.134.dist-info/RECORD +82 -0
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/entry_points.txt +4 -3
- jarvis/jarvis_codebase/__init__.py +0 -0
- jarvis/jarvis_codebase/main.py +0 -1011
- jarvis/jarvis_tools/lsp_find_definition.py +0 -150
- jarvis/jarvis_tools/lsp_find_references.py +0 -127
- 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.134.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,331 @@
|
|
|
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_normal_platform(),
|
|
119
|
+
output_handler=[tool_registry],
|
|
120
|
+
execute_tool_confirm=False,
|
|
121
|
+
auto_complete=True
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
# 运行agent并获取结果
|
|
125
|
+
task_input = f"深入分析 '{function_name}' 函数的内部实现,包括子函数调用、全局变量使用等详细信息"
|
|
126
|
+
result = analyzer_agent.run(task_input)
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
"success": True,
|
|
130
|
+
"stdout": result,
|
|
131
|
+
"stderr": ""
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
except Exception as e:
|
|
135
|
+
PrettyOutput.print(str(e), OutputType.ERROR)
|
|
136
|
+
return {
|
|
137
|
+
"success": False,
|
|
138
|
+
"stdout": "",
|
|
139
|
+
"stderr": f"函数分析失败: {str(e)}"
|
|
140
|
+
}
|
|
141
|
+
finally:
|
|
142
|
+
# 恢复原始目录
|
|
143
|
+
os.chdir(original_dir)
|
|
144
|
+
|
|
145
|
+
def _create_system_prompt(self, function_name: str, file_path: str, root_dir: str,
|
|
146
|
+
file_extensions: List[str], exclude_dirs: List[str],
|
|
147
|
+
analysis_depth: int, objective: str) -> str:
|
|
148
|
+
"""
|
|
149
|
+
创建Agent的system prompt
|
|
150
|
+
|
|
151
|
+
Args:
|
|
152
|
+
function_name: 函数名称
|
|
153
|
+
file_path: 函数所在文件路径
|
|
154
|
+
root_dir: 代码库根目录
|
|
155
|
+
file_extensions: 文件扩展名列表
|
|
156
|
+
exclude_dirs: 排除目录列表
|
|
157
|
+
analysis_depth: 子函数分析深度
|
|
158
|
+
objective: 分析目标
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
系统提示文本
|
|
162
|
+
"""
|
|
163
|
+
file_ext_str = " ".join([f"*{ext}" for ext in file_extensions]) if file_extensions else ""
|
|
164
|
+
exclude_str = " ".join([f"--glob '!{excl}'" for excl in exclude_dirs]) if exclude_dirs else ""
|
|
165
|
+
|
|
166
|
+
depth_description = "不分析子函数" if analysis_depth == 0 else f"分析 {analysis_depth} 层子函数"
|
|
167
|
+
file_info = f"已知文件路径: {file_path}" if file_path else "需要首先查找函数定义位置"
|
|
168
|
+
objective_text = f"\n\n## 分析目标\n{objective}" if objective else ""
|
|
169
|
+
|
|
170
|
+
return f"""# 函数实现分析专家
|
|
171
|
+
|
|
172
|
+
## 任务描述
|
|
173
|
+
分析函数 `{function_name}` 的实现,专注于分析目标所需的信息,生成有针对性的函数分析报告。{objective_text}
|
|
174
|
+
|
|
175
|
+
## 工具使用优先级
|
|
176
|
+
1. **首先使用 execute_shell 执行 rg 命令查找函数定义**:
|
|
177
|
+
- `rg "def\\s+{function_name}\\s*\\(" --type py` 查找Python函数定义
|
|
178
|
+
- `rg "function\\s+{function_name}\\s*\\(" --type js` 查找JavaScript函数定义
|
|
179
|
+
- `rg "func\\s+{function_name}\\s*\\(" --type go` 查找Go函数定义
|
|
180
|
+
|
|
181
|
+
2. **优先使用 read_code 阅读函数实现**:
|
|
182
|
+
- 找到函数位置后使用read_code阅读完整实现
|
|
183
|
+
- 对于长函数可分段读取关键部分
|
|
184
|
+
|
|
185
|
+
3. **使用 rg 搜索子函数调用和使用模式**:
|
|
186
|
+
- `rg -w "子函数名" --type py` 查找子函数调用
|
|
187
|
+
- `rg "import|from" 函数所在文件` 查找导入模块
|
|
188
|
+
|
|
189
|
+
4. **避免使用专用分析工具**:
|
|
190
|
+
- 只有当rg命令和read_code工具无法满足需求时才考虑
|
|
191
|
+
|
|
192
|
+
## 函数信息
|
|
193
|
+
- 函数名称: `{function_name}`
|
|
194
|
+
- {file_info}
|
|
195
|
+
- 分析深度: {depth_description}
|
|
196
|
+
- 代码范围: {file_ext_str if file_ext_str else "所有文件"}
|
|
197
|
+
- 排除目录: {", ".join(exclude_dirs) if exclude_dirs else "无"}
|
|
198
|
+
|
|
199
|
+
## 分析策略
|
|
200
|
+
1. 首先确定项目的主要编程语言和技术栈,以便更准确地分析函数实现
|
|
201
|
+
2. 理解分析目标,明确需要查找的信息
|
|
202
|
+
3. {"在指定文件中定位函数定义" if file_path else "搜索代码库查找函数定义位置"}
|
|
203
|
+
4. 根据分析目标,确定重点分析的方面
|
|
204
|
+
5. 灵活调整分析深度,关注与目标相关的实现细节
|
|
205
|
+
6. 根据目标需要自行判断是否需要分析子函数
|
|
206
|
+
|
|
207
|
+
## 函数分析工具指南
|
|
208
|
+
|
|
209
|
+
### execute_shell 搜索命令
|
|
210
|
+
- **查找函数定义**:
|
|
211
|
+
- `rg "def\\s+{function_name}\\s*\\(" --type py` 查找Python函数定义
|
|
212
|
+
- `rg "function\\s+{function_name}\\s*\\(" --type js` 查找JavaScript函数定义
|
|
213
|
+
- `rg "func\\s+{function_name}\\s*\\(" --type go` 查找Go函数定义
|
|
214
|
+
|
|
215
|
+
- **查找函数调用**:
|
|
216
|
+
- `rg "\\b{function_name}\\s*\\(" --type py` 查找函数调用
|
|
217
|
+
- `rg -w "{function_name}" -A 2 -B 2` 查看函数调用上下文
|
|
218
|
+
|
|
219
|
+
- **分析函数依赖**:
|
|
220
|
+
- `rg "import|from" 函数所在文件` 查找Python导入语句
|
|
221
|
+
- `rg "require\\(" 函数所在文件` 查找JavaScript导入语句
|
|
222
|
+
- `rg "import " 函数所在文件` 查找Go导入语句
|
|
223
|
+
|
|
224
|
+
- **统计分析**:
|
|
225
|
+
- `loc 函数所在文件` 获取文件代码统计
|
|
226
|
+
- `rg -c "if|else|elif" 函数所在文件` 统计条件分支数量
|
|
227
|
+
- `rg -c "for|while" 函数所在文件` 统计循环数量
|
|
228
|
+
|
|
229
|
+
### read_code
|
|
230
|
+
- **用途**:读取函数实现和相关代码
|
|
231
|
+
- **典型用法**:
|
|
232
|
+
- 阅读完整函数实现,包括注释和文档
|
|
233
|
+
- 阅读关键子函数的实现(根据analysis_depth)
|
|
234
|
+
- 阅读使用到的关键变量和依赖组件定义
|
|
235
|
+
- **使用策略**:
|
|
236
|
+
- 首先阅读整个函数以获取完整视图
|
|
237
|
+
- 识别函数的主要逻辑分支和处理路径
|
|
238
|
+
- 重点关注错误处理和边界条件检查
|
|
239
|
+
- 对复杂子函数进行递归分析(不超过指定深度)
|
|
240
|
+
|
|
241
|
+
### 函数分析模式
|
|
242
|
+
|
|
243
|
+
1. **逻辑流程分析**:
|
|
244
|
+
- 识别函数的主要执行路径
|
|
245
|
+
- 分析条件分支和循环结构
|
|
246
|
+
- 构建完整的逻辑流程图
|
|
247
|
+
|
|
248
|
+
2. **参数分析**:
|
|
249
|
+
- 分析参数类型、默认值和约束条件
|
|
250
|
+
- 了解参数在函数中的使用方式
|
|
251
|
+
- 识别关键参数及其影响
|
|
252
|
+
|
|
253
|
+
3. **依赖与副作用分析**:
|
|
254
|
+
- 识别函数使用的外部变量和组件
|
|
255
|
+
- 分析函数对外部状态的修改
|
|
256
|
+
- 评估函数的纯度和可测试性
|
|
257
|
+
|
|
258
|
+
4. **异常处理分析**:
|
|
259
|
+
- 识别可能的异常和错误情况
|
|
260
|
+
- 分析错误处理和恢复机制
|
|
261
|
+
- 评估错误处理的完整性和合理性
|
|
262
|
+
|
|
263
|
+
5. **性能分析**:
|
|
264
|
+
- 识别潜在的性能瓶颈
|
|
265
|
+
- 分析循环和递归的效率
|
|
266
|
+
- 评估算法复杂度
|
|
267
|
+
|
|
268
|
+
6. **子函数调用分析**:
|
|
269
|
+
- 识别所有调用的子函数
|
|
270
|
+
- 分析子函数的作用和调用模式
|
|
271
|
+
- 在允许的深度内递归分析关键子函数
|
|
272
|
+
|
|
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
|
+
def _create_summary_prompt(self, function_name: str, analysis_depth: int) -> str:
|
|
306
|
+
"""
|
|
307
|
+
创建Agent的summary prompt
|
|
308
|
+
|
|
309
|
+
Args:
|
|
310
|
+
function_name: 函数名称
|
|
311
|
+
analysis_depth: 子函数分析深度
|
|
312
|
+
|
|
313
|
+
Returns:
|
|
314
|
+
总结提示文本
|
|
315
|
+
"""
|
|
316
|
+
depth_description = "不包含子函数分析" if analysis_depth == 0 else f"包含 {analysis_depth} 层子函数分析"
|
|
317
|
+
|
|
318
|
+
return f"""# 函数分析报告: `{function_name}`
|
|
319
|
+
|
|
320
|
+
## 报告要求
|
|
321
|
+
生成一份完全以分析目标为导向的函数分析报告,{depth_description}。不要遵循固定的报告模板,而是完全根据分析目标来组织内容:
|
|
322
|
+
|
|
323
|
+
- 首先简要说明项目的主要编程语言和技术栈
|
|
324
|
+
- 专注回答分析目标提出的问题
|
|
325
|
+
- 只包含与分析目标直接相关的实现发现和洞察
|
|
326
|
+
- 完全跳过与分析目标无关的内容,无需做全面分析
|
|
327
|
+
- 分析深度应与目标的具体需求匹配
|
|
328
|
+
- 使用具体的代码片段支持你的观点
|
|
329
|
+
- 以清晰的Markdown格式呈现,简洁明了
|
|
330
|
+
|
|
331
|
+
在分析中保持灵活性,避免固定思维模式。你的任务不是提供全面的函数概览,而是直接解决分析目标中提出的具体问题。"""
|
|
@@ -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)
|
|
@@ -110,7 +110,7 @@ class GitCommitTool:
|
|
|
110
110
|
# 分析材料
|
|
111
111
|
{diff}
|
|
112
112
|
'''
|
|
113
|
-
platform = PlatformRegistry().
|
|
113
|
+
platform = PlatformRegistry().get_normal_platform()
|
|
114
114
|
commit_message = platform.chat_until_success(prompt)
|
|
115
115
|
commit_message = self._extract_commit_message(commit_message)
|
|
116
116
|
spinner.write("✅ 生成提交消息")
|
|
@@ -1,8 +1,9 @@
|
|
|
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
|
-
from jarvis.jarvis_utils.config import is_use_methodology
|
|
6
7
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
7
8
|
|
|
8
9
|
|
|
@@ -32,54 +33,66 @@ class MethodologyTool:
|
|
|
32
33
|
},
|
|
33
34
|
"required": ["operation", "problem_type"]
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
@staticmethod
|
|
37
|
-
def check()->bool:
|
|
38
|
-
"""Check if the methodology is enabled"""
|
|
39
|
-
return is_use_methodology()
|
|
40
36
|
|
|
41
37
|
def __init__(self):
|
|
42
|
-
"""
|
|
43
|
-
self.
|
|
44
|
-
self.
|
|
38
|
+
"""初始化经验管理工具"""
|
|
39
|
+
self.methodology_dir = os.path.expanduser("~/.jarvis/methodologies")
|
|
40
|
+
self._ensure_dir_exists()
|
|
45
41
|
|
|
46
|
-
def
|
|
47
|
-
"""
|
|
48
|
-
if not os.path.exists(self.
|
|
42
|
+
def _ensure_dir_exists(self):
|
|
43
|
+
"""确保方法论目录存在"""
|
|
44
|
+
if not os.path.exists(self.methodology_dir):
|
|
49
45
|
try:
|
|
50
|
-
|
|
51
|
-
yaml.safe_dump({}, f, allow_unicode=True)
|
|
46
|
+
os.makedirs(self.methodology_dir, exist_ok=True)
|
|
52
47
|
except Exception as e:
|
|
53
|
-
PrettyOutput.print(f"
|
|
54
|
-
|
|
55
|
-
def
|
|
56
|
-
"""
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
PrettyOutput.print(f"创建方法论目录失败:{str(e)}", OutputType.ERROR)
|
|
49
|
+
|
|
50
|
+
def _get_methodology_file_path(self, problem_type: str) -> str:
|
|
51
|
+
"""
|
|
52
|
+
根据问题类型获取对应的方法论文件路径
|
|
53
|
+
|
|
54
|
+
参数:
|
|
55
|
+
problem_type: 问题类型
|
|
56
|
+
|
|
57
|
+
返回:
|
|
58
|
+
str: 方法论文件路径
|
|
59
|
+
"""
|
|
60
|
+
# 使用MD5哈希作为文件名,避免文件名中的特殊字符
|
|
61
|
+
safe_filename = hashlib.md5(problem_type.encode('utf-8')).hexdigest()
|
|
62
|
+
return os.path.join(self.methodology_dir, f"{safe_filename}.json")
|
|
63
63
|
|
|
64
|
-
def
|
|
65
|
-
"""
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
def _load_methodologies(self) -> Dict[str, str]:
|
|
65
|
+
"""加载所有方法论"""
|
|
66
|
+
all_methodologies = {}
|
|
67
|
+
|
|
68
|
+
if not os.path.exists(self.methodology_dir):
|
|
69
|
+
return all_methodologies
|
|
70
|
+
|
|
71
|
+
for filepath in glob.glob(os.path.join(self.methodology_dir, "*.json")):
|
|
72
|
+
try:
|
|
73
|
+
with open(filepath, "r", encoding="utf-8", errors="ignore") as f:
|
|
74
|
+
methodology = json.load(f)
|
|
75
|
+
problem_type = methodology.get("problem_type", "")
|
|
76
|
+
content = methodology.get("content", "")
|
|
77
|
+
if problem_type and content:
|
|
78
|
+
all_methodologies[problem_type] = content
|
|
79
|
+
except Exception as e:
|
|
80
|
+
filename = os.path.basename(filepath)
|
|
81
|
+
PrettyOutput.print(f"加载方法论文件 {filename} 失败: {str(e)}", OutputType.WARNING)
|
|
82
|
+
|
|
83
|
+
return all_methodologies
|
|
71
84
|
|
|
72
85
|
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
|
73
|
-
"""
|
|
86
|
+
"""执行管理方法论的操作
|
|
74
87
|
|
|
75
88
|
Args:
|
|
76
|
-
args:
|
|
77
|
-
- operation:
|
|
78
|
-
- problem_type:
|
|
79
|
-
- content:
|
|
89
|
+
args: 包含操作参数的字典
|
|
90
|
+
- operation: 操作类型 (delete/update/add)
|
|
91
|
+
- problem_type: 问题类型
|
|
92
|
+
- content: 方法论内容 (更新和添加时必填)
|
|
80
93
|
|
|
81
94
|
Returns:
|
|
82
|
-
Dict[str, Any]:
|
|
95
|
+
Dict[str, Any]: 包含执行结果的字典
|
|
83
96
|
"""
|
|
84
97
|
operation = args.get("operation", "").strip()
|
|
85
98
|
problem_type = args.get("problem_type", "").strip()
|
|
@@ -92,16 +105,18 @@ class MethodologyTool:
|
|
|
92
105
|
"stderr": "Missing required parameters: operation and problem_type"
|
|
93
106
|
}
|
|
94
107
|
|
|
95
|
-
methodologies = self._load_methodologies()
|
|
96
|
-
|
|
97
108
|
try:
|
|
98
109
|
if operation == "delete":
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
110
|
+
# 获取方法论文件路径
|
|
111
|
+
file_path = self._get_methodology_file_path(problem_type)
|
|
112
|
+
|
|
113
|
+
# 检查文件是否存在
|
|
114
|
+
if os.path.exists(file_path):
|
|
115
|
+
os.remove(file_path)
|
|
102
116
|
return {
|
|
103
117
|
"success": True,
|
|
104
|
-
"stdout": f"Deleted methodology for problem type '{problem_type}'"
|
|
118
|
+
"stdout": f"Deleted methodology for problem type '{problem_type}'",
|
|
119
|
+
"stderr": ""
|
|
105
120
|
}
|
|
106
121
|
else:
|
|
107
122
|
return {
|
|
@@ -117,11 +132,21 @@ class MethodologyTool:
|
|
|
117
132
|
"stdout": "",
|
|
118
133
|
"stderr": "Need to provide methodology content"
|
|
119
134
|
}
|
|
120
|
-
|
|
121
|
-
methodologies[problem_type] = content
|
|
122
|
-
self._save_methodologies(methodologies)
|
|
123
135
|
|
|
124
|
-
|
|
136
|
+
# 确保目录存在
|
|
137
|
+
self._ensure_dir_exists()
|
|
138
|
+
|
|
139
|
+
# 获取方法论文件路径
|
|
140
|
+
file_path = self._get_methodology_file_path(problem_type)
|
|
141
|
+
|
|
142
|
+
# 保存方法论到单独的文件
|
|
143
|
+
with open(file_path, "w", encoding="utf-8", errors="ignore") as f:
|
|
144
|
+
json.dump({
|
|
145
|
+
"problem_type": problem_type,
|
|
146
|
+
"content": content
|
|
147
|
+
}, f, ensure_ascii=False, indent=2)
|
|
148
|
+
|
|
149
|
+
action = "Updated" if os.path.exists(file_path) else "Added"
|
|
125
150
|
return {
|
|
126
151
|
"success": True,
|
|
127
152
|
"stdout": f"{action} methodology for problem type '{problem_type}'",
|
|
@@ -143,13 +168,23 @@ class MethodologyTool:
|
|
|
143
168
|
}
|
|
144
169
|
|
|
145
170
|
def get_methodology(self, problem_type: str) -> Optional[str]:
|
|
146
|
-
"""
|
|
171
|
+
"""获取特定问题类型的方法论
|
|
147
172
|
|
|
148
173
|
Args:
|
|
149
|
-
problem_type:
|
|
174
|
+
problem_type: 问题类型
|
|
150
175
|
|
|
151
176
|
Returns:
|
|
152
|
-
Optional[str]:
|
|
177
|
+
Optional[str]: 方法论内容,如果不存在则返回 None
|
|
153
178
|
"""
|
|
154
|
-
|
|
155
|
-
|
|
179
|
+
file_path = self._get_methodology_file_path(problem_type)
|
|
180
|
+
|
|
181
|
+
if not os.path.exists(file_path):
|
|
182
|
+
return None
|
|
183
|
+
|
|
184
|
+
try:
|
|
185
|
+
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
|
186
|
+
methodology = json.load(f)
|
|
187
|
+
return methodology.get("content")
|
|
188
|
+
except Exception as e:
|
|
189
|
+
PrettyOutput.print(f"读取方法论失败: {str(e)}", OutputType.ERROR)
|
|
190
|
+
return None
|