jarvis-ai-assistant 0.1.138__py3-none-any.whl → 0.1.141__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.

Files changed (85) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +62 -14
  3. jarvis/jarvis_agent/builtin_input_handler.py +4 -14
  4. jarvis/jarvis_agent/main.py +1 -1
  5. jarvis/jarvis_agent/patch.py +37 -40
  6. jarvis/jarvis_agent/shell_input_handler.py +2 -3
  7. jarvis/jarvis_code_agent/code_agent.py +23 -30
  8. jarvis/jarvis_code_analysis/checklists/__init__.py +3 -0
  9. jarvis/jarvis_code_analysis/checklists/c_cpp.py +50 -0
  10. jarvis/jarvis_code_analysis/checklists/csharp.py +75 -0
  11. jarvis/jarvis_code_analysis/checklists/data_format.py +82 -0
  12. jarvis/jarvis_code_analysis/checklists/devops.py +107 -0
  13. jarvis/jarvis_code_analysis/checklists/docs.py +87 -0
  14. jarvis/jarvis_code_analysis/checklists/go.py +52 -0
  15. jarvis/jarvis_code_analysis/checklists/infrastructure.py +98 -0
  16. jarvis/jarvis_code_analysis/checklists/java.py +66 -0
  17. jarvis/jarvis_code_analysis/checklists/javascript.py +73 -0
  18. jarvis/jarvis_code_analysis/checklists/kotlin.py +107 -0
  19. jarvis/jarvis_code_analysis/checklists/loader.py +76 -0
  20. jarvis/jarvis_code_analysis/checklists/php.py +77 -0
  21. jarvis/jarvis_code_analysis/checklists/python.py +56 -0
  22. jarvis/jarvis_code_analysis/checklists/ruby.py +107 -0
  23. jarvis/jarvis_code_analysis/checklists/rust.py +58 -0
  24. jarvis/jarvis_code_analysis/checklists/shell.py +75 -0
  25. jarvis/jarvis_code_analysis/checklists/sql.py +72 -0
  26. jarvis/jarvis_code_analysis/checklists/swift.py +77 -0
  27. jarvis/jarvis_code_analysis/checklists/web.py +97 -0
  28. jarvis/jarvis_code_analysis/code_review.py +660 -0
  29. jarvis/jarvis_dev/main.py +61 -88
  30. jarvis/jarvis_git_squash/main.py +3 -3
  31. jarvis/jarvis_git_utils/git_commiter.py +242 -0
  32. jarvis/jarvis_init/main.py +62 -0
  33. jarvis/jarvis_platform/base.py +4 -0
  34. jarvis/jarvis_platform/kimi.py +173 -5
  35. jarvis/jarvis_platform/openai.py +3 -0
  36. jarvis/jarvis_platform/registry.py +1 -0
  37. jarvis/jarvis_platform/yuanbao.py +275 -5
  38. jarvis/jarvis_tools/ask_codebase.py +6 -9
  39. jarvis/jarvis_tools/ask_user.py +17 -5
  40. jarvis/jarvis_tools/base.py +3 -1
  41. jarvis/jarvis_tools/chdir.py +1 -0
  42. jarvis/jarvis_tools/create_code_agent.py +4 -3
  43. jarvis/jarvis_tools/create_sub_agent.py +1 -0
  44. jarvis/jarvis_tools/execute_script.py +170 -0
  45. jarvis/jarvis_tools/file_analyzer.py +90 -239
  46. jarvis/jarvis_tools/file_operation.py +99 -31
  47. jarvis/jarvis_tools/{find_methodolopy.py → find_methodology.py} +2 -1
  48. jarvis/jarvis_tools/lsp_get_diagnostics.py +2 -0
  49. jarvis/jarvis_tools/methodology.py +11 -11
  50. jarvis/jarvis_tools/read_code.py +2 -0
  51. jarvis/jarvis_tools/read_webpage.py +33 -196
  52. jarvis/jarvis_tools/registry.py +68 -131
  53. jarvis/jarvis_tools/search_web.py +14 -6
  54. jarvis/jarvis_tools/virtual_tty.py +399 -0
  55. jarvis/jarvis_utils/config.py +29 -3
  56. jarvis/jarvis_utils/embedding.py +0 -317
  57. jarvis/jarvis_utils/file_processors.py +343 -0
  58. jarvis/jarvis_utils/input.py +0 -1
  59. jarvis/jarvis_utils/methodology.py +94 -435
  60. jarvis/jarvis_utils/utils.py +207 -9
  61. {jarvis_ai_assistant-0.1.138.dist-info → jarvis_ai_assistant-0.1.141.dist-info}/METADATA +4 -4
  62. jarvis_ai_assistant-0.1.141.dist-info/RECORD +94 -0
  63. {jarvis_ai_assistant-0.1.138.dist-info → jarvis_ai_assistant-0.1.141.dist-info}/entry_points.txt +4 -4
  64. jarvis/jarvis_code_agent/file_select.py +0 -202
  65. jarvis/jarvis_platform/ai8.py +0 -268
  66. jarvis/jarvis_platform/ollama.py +0 -137
  67. jarvis/jarvis_platform/oyi.py +0 -307
  68. jarvis/jarvis_rag/file_processors.py +0 -138
  69. jarvis/jarvis_rag/main.py +0 -1734
  70. jarvis/jarvis_tools/code_review.py +0 -333
  71. jarvis/jarvis_tools/execute_python_script.py +0 -58
  72. jarvis/jarvis_tools/execute_shell.py +0 -97
  73. jarvis/jarvis_tools/execute_shell_script.py +0 -58
  74. jarvis/jarvis_tools/find_caller.py +0 -278
  75. jarvis/jarvis_tools/find_symbol.py +0 -295
  76. jarvis/jarvis_tools/function_analyzer.py +0 -331
  77. jarvis/jarvis_tools/git_commiter.py +0 -167
  78. jarvis/jarvis_tools/project_analyzer.py +0 -304
  79. jarvis/jarvis_tools/rag.py +0 -143
  80. jarvis/jarvis_tools/tool_generator.py +0 -221
  81. jarvis_ai_assistant-0.1.138.dist-info/RECORD +0 -85
  82. /jarvis/{jarvis_rag → jarvis_init}/__init__.py +0 -0
  83. {jarvis_ai_assistant-0.1.138.dist-info → jarvis_ai_assistant-0.1.141.dist-info}/LICENSE +0 -0
  84. {jarvis_ai_assistant-0.1.138.dist-info → jarvis_ai_assistant-0.1.141.dist-info}/WHEEL +0 -0
  85. {jarvis_ai_assistant-0.1.138.dist-info → jarvis_ai_assistant-0.1.141.dist-info}/top_level.txt +0 -0
@@ -1,278 +0,0 @@
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 FindCallerTool:
10
- """
11
- 函数调用者查找工具
12
- 使用agent查找代码库中所有调用指定函数的位置
13
- """
14
-
15
- name = "find_caller"
16
- description = "查找所有调用指定函数的代码位置"
17
- parameters = {
18
- "type": "object",
19
- "properties": {
20
- "function_name": {
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": ["function_name"]
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
- function_name = args.get("function_name", "")
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 function_name:
77
- return {
78
- "success": False,
79
- "stdout": "",
80
- "stderr": "必须提供函数名称"
81
- }
82
-
83
- # 创建agent的system prompt
84
- system_prompt = self._create_system_prompt(
85
- function_name, root_dir, file_extensions, exclude_dirs, objective
86
- )
87
-
88
- # 创建agent的summary prompt
89
- summary_prompt = self._create_summary_prompt(function_name)
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
- caller_agent = Agent(
101
- system_prompt=system_prompt,
102
- name=f"CallerFinder-{function_name}",
103
- description=f"查找 '{function_name}' 函数的所有调用位置",
104
- summary_prompt=summary_prompt,
105
- platform=PlatformRegistry().get_normal_platform(),
106
- output_handler=[tool_registry],
107
- execute_tool_confirm=False,
108
- auto_complete=True
109
- )
110
-
111
- # 运行agent并获取结果
112
- task_input = f"查找所有调用 '{function_name}' 函数的代码位置"
113
- result = caller_agent.run(task_input)
114
-
115
- return {
116
- "success": True,
117
- "stdout": result,
118
- "stderr": ""
119
- }
120
-
121
- except Exception as e:
122
- PrettyOutput.print(str(e), OutputType.ERROR)
123
- return {
124
- "success": False,
125
- "stdout": "",
126
- "stderr": f"查找调用者失败: {str(e)}"
127
- }
128
- finally:
129
- # 恢复原始目录
130
- os.chdir(original_dir)
131
-
132
- def _create_system_prompt(self, function_name: str, root_dir: str,
133
- file_extensions: List[str], exclude_dirs: List[str],
134
- objective: str) -> str:
135
- """
136
- 创建Agent的system prompt
137
-
138
- Args:
139
- function_name: 函数名称
140
- root_dir: 代码库根目录
141
- file_extensions: 文件扩展名列表
142
- exclude_dirs: 排除目录列表
143
- objective: 分析目标
144
-
145
- Returns:
146
- 系统提示文本
147
- """
148
- file_ext_str = " ".join([f"*{ext}" for ext in file_extensions]) if file_extensions else ""
149
- exclude_str = " ".join([f"--glob '!{excl}'" for excl in exclude_dirs]) if exclude_dirs else ""
150
- objective_text = f"\n\n## 分析目标\n{objective}" if objective else ""
151
-
152
- search_pattern = f"\\b{function_name}\\s*\\("
153
-
154
- return f"""# 函数调用分析专家
155
-
156
- ## 任务描述
157
- 查找所有调用 `{function_name}` 函数的代码位置,专注于分析目标所需的信息,生成有针对性的调用分析报告。{objective_text}
158
-
159
- ## 工具使用优先级
160
- 1. **优先使用 execute_shell 执行 rg 命令**:
161
- - `rg "\\b{function_name}\\s*\\(" --type py` 查找Python文件中的调用
162
- - `rg "\\b{function_name}\\s*\\(" --type js` 查找JavaScript文件中的调用
163
- - `rg -w "{function_name}" -A 2 -B 2` 查看调用上下文
164
-
165
- 2. **辅以 read_code**:
166
- - 找到调用位置后使用read_code阅读上下文
167
- - 读取关键调用者的完整实现
168
-
169
- 3. **避免使用专用分析工具**:
170
- - 只有当rg命令和read_code工具无法满足需求时才考虑
171
-
172
- ## 工作环境
173
- - 工作目录: `{root_dir}`
174
- - 文件类型: {file_ext_str if file_ext_str else "所有文件"}
175
- - 排除目录: {", ".join(exclude_dirs) if exclude_dirs else "无"}
176
-
177
- ## 分析策略
178
- 1. 首先确定项目的主要编程语言和技术栈,以便更精确地查找函数调用
179
- 2. 理解分析目标,明确需要查找的信息类型
180
- 3. 使用适当的rg搜索模式查找函数调用
181
- 4. 验证搜索结果,确认是对目标函数的真正调用
182
- 5. 分析调用上下文,了解调用的目的和方式
183
- 6. 根据分析目标自行确定需要的分析深度和广度
184
-
185
- ## 调用者查找工具指南
186
-
187
- ### execute_shell 搜索命令
188
- - **基本搜索**:
189
- - `rg "\\b{function_name}\\s*\\(" --type=文件类型`
190
- - 示例: `rg "\\b{function_name}\\s*\\(" --type py` 搜索Python文件中的调用
191
-
192
- - **查看上下文**:
193
- - `rg "\\b{function_name}\\s*\\(" -A 5 -B 5` 显示调用前后5行
194
- - `rg "\\b{function_name}\\s*\\(" --context=10` 显示调用前后10行
195
-
196
- - **排除目录**:
197
- - `rg "\\b{function_name}\\s*\\(" --type py -g '!tests/'` 排除测试目录
198
- - `rg "\\b{function_name}\\s*\\(" -g '!node_modules/'` 排除node_modules
199
-
200
- - **统计调用**:
201
- - `rg -c "\\b{function_name}\\s*\\(" --type py` 统计每个Python文件中的调用次数
202
- - `rg "\\b{function_name}\\s*\\(" --count-matches --stats` 显示调用统计信息
203
-
204
- ### read_code
205
- - **用途**:读取找到的调用点上下文
206
- - **典型用法**:
207
- - 读取调用函数的整个方法或类
208
- - 读取调用点的上下文行(前后5-10行)
209
- - **使用策略**:
210
- - 首先读取足够的上下文以理解调用目的
211
- - 对于复杂调用,可能需要读取整个调用函数
212
- - 关注调用前的参数准备和调用后的结果处理
213
-
214
- ### 调用者分析模式
215
-
216
- 1. **影响范围评估模式**:
217
- - 查找所有调用点: `rg -l "\\b{function_name}\\s*\\("`
218
- - 按模块/组件分类调用位置
219
- - 评估修改函数可能影响的范围和严重性
220
-
221
- 2. **使用模式分析**:
222
- - 分析各调用点的参数传递方式
223
- - 识别典型的调用模式和变体
224
- - 总结函数的不同使用场景
225
-
226
- 3. **依赖关系追踪**:
227
- - 识别直接调用者
228
- - 分析这些调用者自身被谁调用
229
- - 构建完整的调用链或调用树
230
-
231
- 4. **调用频率分析**:
232
- - 统计不同模块中的调用频率: `rg -c "\\b{function_name}\\s*\\(" --sort path`
233
- - 识别高频调用点和关键路径
234
- - 评估函数在系统中的重要性
235
-
236
- 5. **异常使用检测**:
237
- - 检查是否存在异常的调用模式
238
- - 识别可能存在问题的调用点
239
- - 提出优化或修正建议
240
-
241
- ## 搜索技巧
242
- - 根据不同编程语言调整函数调用模式的搜索方式
243
- - 考虑各种编程范式下的不同调用方式(面向对象、函数式等)
244
- - 考虑函数可能通过变量或回调方式间接调用
245
- - 检查可能存在的同名函数,确保找到的是目标函数的调用
246
-
247
- ## 输出要求
248
- - 直接回应分析目标的关键问题
249
- - 提供与目标相关的调用信息
250
- - 分析内容应直接服务于分析目标
251
- - 避免与目标无关的冗余信息
252
- - 使用具体代码路径和调用示例支持分析结论
253
- - 提供针对分析目标的具体见解和建议"""
254
-
255
- def _create_summary_prompt(self, function_name: str) -> str:
256
- """
257
- 创建Agent的summary prompt
258
-
259
- Args:
260
- function_name: 函数名称
261
-
262
- Returns:
263
- 总结提示文本
264
- """
265
- return f"""# 函数 `{function_name}` 调用分析报告
266
-
267
- ## 报告要求
268
- 生成一份完全以分析目标为导向的函数调用分析报告。不要遵循固定的报告模板,而是完全根据分析目标来组织内容:
269
-
270
- - 首先简要说明项目的主要编程语言和技术栈
271
- - 专注回答分析目标提出的问题
272
- - 只包含与分析目标直接相关的调用发现和洞察
273
- - 完全跳过与分析目标无关的内容,无需做全面分析
274
- - 分析深度应与目标的具体需求匹配
275
- - 使用具体的代码调用示例支持你的观点
276
- - 以清晰的Markdown格式呈现,简洁明了
277
-
278
- 在分析中保持灵活性,避免固定思维模式。你的任务不是提供全面的函数调用概览,而是直接解决分析目标中提出的具体问题。"""
@@ -1,295 +0,0 @@
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_normal_platform(),
106
- output_handler=[tool_registry],
107
- execute_tool_confirm=False,
108
- auto_complete=True
109
- )
110
-
111
- # 运行agent并获取结果
112
- task_input = f"查找符号 '{symbol}' 在代码库中的引用、定义和声明位置"
113
- result = symbol_agent.run(task_input)
114
-
115
- return {
116
- "success": True,
117
- "stdout": result,
118
- "stderr": ""
119
- }
120
-
121
- except Exception as e:
122
- PrettyOutput.print(str(e), OutputType.ERROR)
123
- return {
124
- "success": False,
125
- "stdout": "",
126
- "stderr": f"符号查找失败: {str(e)}"
127
- }
128
- finally:
129
- # 恢复原始目录
130
- os.chdir(original_dir)
131
-
132
- def _create_system_prompt(self, symbol: str, root_dir: str,
133
- file_extensions: List[str], exclude_dirs: List[str],
134
- objective: str) -> str:
135
- """
136
- 创建Agent的system prompt
137
-
138
- Args:
139
- symbol: 符号名称
140
- root_dir: 代码库根目录
141
- file_extensions: 文件扩展名列表
142
- exclude_dirs: 排除目录列表
143
- objective: 分析目标
144
-
145
- Returns:
146
- 系统提示文本
147
- """
148
- file_ext_str = " ".join([f"*{ext}" for ext in file_extensions]) if file_extensions else ""
149
- exclude_str = " ".join([f"--glob '!{excl}'" for excl in exclude_dirs]) if exclude_dirs else ""
150
- objective_text = f"\n\n## 分析目标\n{objective}" if objective else ""
151
-
152
- return f"""# 代码符号分析专家
153
-
154
- ## 任务描述
155
- 查找符号 `{symbol}` 在代码库中的定义、声明和引用位置,专注于分析目标所需的信息,生成有针对性的符号分析报告。{objective_text}
156
-
157
- ## 工具使用优先级
158
- 1. **优先使用 execute_shell 执行 rg 命令**:
159
- - `rg -w "{symbol}" --type py` 查找Python文件中的符号
160
- - `rg "class\\s+{symbol}|def\\s+{symbol}" --type py` 查找定义
161
- - `rg -w "{symbol}" -A 2 -B 2` 查看符号上下文
162
-
163
- 2. **辅以 read_code**:
164
- - 找到符号位置后使用read_code阅读上下文
165
- - 读取符号定义和关键引用的完整实现
166
-
167
- 3. **避免使用专用分析工具**:
168
- - 只有当rg命令和read_code工具无法满足需求时才考虑
169
-
170
- ## 工作环境
171
- - 工作目录: `{root_dir}`
172
- - 文件类型: {file_ext_str if file_ext_str else "所有文件"}
173
- - 排除目录: {", ".join(exclude_dirs) if exclude_dirs else "无"}
174
-
175
- ## 分析策略
176
- 1. 首先确定项目的主要编程语言和技术栈,以便更精确地查找符号
177
- 2. 理解分析目标,明确需要查找的信息类型
178
- 3. 使用适当的rg搜索模式查找符号定义和引用
179
- 4. 验证搜索结果,确认是目标符号的真正使用
180
- 5. 分析符号上下文,了解其用途和使用方式
181
- 6. 根据分析目标自行确定需要的分析深度和广度
182
-
183
- ## 符号查找工具指南
184
-
185
- ### execute_shell 搜索命令
186
- - **基本搜索**:
187
- - `rg -w "{symbol}" --type=文件类型`
188
- - 示例: `rg -w "{symbol}" --type py` 搜索Python文件中的符号
189
-
190
- - **查找定义**:
191
- - `rg "class\\s+{symbol}\\b|def\\s+{symbol}\\b|function\\s+{symbol}\\b" --type py` 查找Python定义
192
- - `rg "class\\s+{symbol}\\b|function\\s+{symbol}\\b" --type js` 查找JavaScript定义
193
- - `rg "const\\s+{symbol}\\b|let\\s+{symbol}\\b|var\\s+{symbol}\\b" --type js` 查找JavaScript变量声明
194
-
195
- - **查看上下文**:
196
- - `rg -w "{symbol}" -A 5 -B 5` 显示符号前后5行
197
- - `rg -w "{symbol}" --context=10` 显示符号前后10行
198
-
199
- - **排除目录**:
200
- - `rg -w "{symbol}" --type py -g '!tests/'` 排除测试目录
201
- - `rg -w "{symbol}" -g '!node_modules/'` 排除node_modules
202
-
203
- - **统计引用**:
204
- - `rg -c -w "{symbol}" --type py` 统计每个Python文件中的引用次数
205
- - `rg -w "{symbol}" --count-matches --stats` 显示引用统计信息
206
-
207
- ### read_code
208
- - **用途**:读取符号定义和使用的上下文
209
- - **典型用法**:
210
- - 读取符号定义所在的文件区域
211
- - 读取关键使用位置的上下文
212
- - **使用策略**:
213
- - 首先读取符号的定义以理解其属性和行为
214
- - 然后读取典型使用场景的代码
215
- - 重点关注频繁使用的模式和关键功能点
216
-
217
- ### 符号分析模式
218
-
219
- 1. **定义分析模式**:
220
- - 首先找到符号的所有定义位置
221
- - 分析定义的类型(类、函数、变量、常量等)
222
- - 理解符号的属性、参数、返回值等特性
223
- - 查看相关注释和文档字符串
224
-
225
- 2. **使用模式分析**:
226
- - 分类统计不同类型的使用方式
227
- - 识别典型的使用模式和上下文
228
- - 总结符号的主要用途和功能
229
-
230
- 3. **影响范围评估**:
231
- - 统计符号在不同模块中的使用频率
232
- - 分析符号修改可能影响的代码范围
233
- - 识别关键依赖点和潜在风险区域
234
-
235
- 4. **符号关系网络分析**:
236
- - 分析与目标符号相关的其他符号
237
- - 识别依赖该符号的组件
238
- - 了解该符号依赖的其他组件
239
-
240
- ## 编程范式适应
241
-
242
- 无论项目使用什么编程语言或范式,符号分析都应考虑以下方面:
243
-
244
- ### 对象导向程序
245
- - 类定义、继承关系和实例化
246
- - 方法重载和覆盖
247
- - 成员变量和属性访问
248
-
249
- ### 函数式编程
250
- - 高阶函数和函数传递
251
- - 不可变数据结构
252
- - 闭包和作用域
253
-
254
- ### 过程式编程
255
- - 全局和局部变量
256
- - 函数调用关系
257
- - 数据流动
258
-
259
- ### 声明式编程
260
- - 规则和约束定义
261
- - 模式匹配
262
- - 数据转换
263
-
264
- ## 输出要求
265
- - 直接回应分析目标的关键问题
266
- - 提供与目标相关的符号信息
267
- - 分析内容应直接服务于分析目标
268
- - 避免与目标无关的冗余信息
269
- - 使用具体代码路径和使用示例支持分析结论
270
- - 提供针对分析目标的具体见解和建议"""
271
-
272
- def _create_summary_prompt(self, symbol: str) -> str:
273
- """
274
- 创建Agent的summary prompt
275
-
276
- Args:
277
- symbol: 符号名称
278
-
279
- Returns:
280
- 总结提示文本
281
- """
282
- return f"""# 符号 `{symbol}` 分析报告
283
-
284
- ## 报告要求
285
- 生成一份完全以分析目标为导向的符号分析报告。不要遵循固定的报告模板,而是完全根据分析目标来组织内容:
286
-
287
- - 首先简要说明项目的主要编程语言和技术栈
288
- - 专注回答分析目标提出的问题
289
- - 只包含与分析目标直接相关的符号发现和洞察
290
- - 完全跳过与分析目标无关的内容,无需做全面分析
291
- - 分析深度应与目标的具体需求匹配
292
- - 使用具体的代码示例支持你的观点
293
- - 以清晰的Markdown格式呈现,简洁明了
294
-
295
- 在分析中保持灵活性,避免固定思维模式。你的任务不是提供全面的符号概览,而是直接解决分析目标中提出的具体问题。"""