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.
Files changed (61) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +48 -29
  3. jarvis/jarvis_agent/patch.py +61 -43
  4. jarvis/jarvis_agent/shell_input_handler.py +1 -1
  5. jarvis/jarvis_code_agent/code_agent.py +87 -86
  6. jarvis/jarvis_dev/main.py +335 -626
  7. jarvis/jarvis_git_squash/main.py +10 -31
  8. jarvis/jarvis_multi_agent/__init__.py +19 -28
  9. jarvis/jarvis_platform/ai8.py +7 -32
  10. jarvis/jarvis_platform/base.py +2 -7
  11. jarvis/jarvis_platform/kimi.py +3 -144
  12. jarvis/jarvis_platform/ollama.py +54 -68
  13. jarvis/jarvis_platform/openai.py +0 -4
  14. jarvis/jarvis_platform/oyi.py +0 -75
  15. jarvis/jarvis_platform/yuanbao.py +264 -0
  16. jarvis/jarvis_rag/file_processors.py +138 -0
  17. jarvis/jarvis_rag/main.py +1305 -425
  18. jarvis/jarvis_tools/ask_codebase.py +205 -39
  19. jarvis/jarvis_tools/code_review.py +125 -99
  20. jarvis/jarvis_tools/execute_python_script.py +58 -0
  21. jarvis/jarvis_tools/execute_shell.py +13 -26
  22. jarvis/jarvis_tools/execute_shell_script.py +1 -1
  23. jarvis/jarvis_tools/file_analyzer.py +271 -0
  24. jarvis/jarvis_tools/file_operation.py +1 -1
  25. jarvis/jarvis_tools/find_caller.py +213 -0
  26. jarvis/jarvis_tools/find_symbol.py +211 -0
  27. jarvis/jarvis_tools/function_analyzer.py +248 -0
  28. jarvis/jarvis_tools/git_commiter.py +4 -4
  29. jarvis/jarvis_tools/methodology.py +89 -48
  30. jarvis/jarvis_tools/project_analyzer.py +220 -0
  31. jarvis/jarvis_tools/read_code.py +23 -2
  32. jarvis/jarvis_tools/read_webpage.py +195 -81
  33. jarvis/jarvis_tools/registry.py +132 -11
  34. jarvis/jarvis_tools/search_web.py +55 -10
  35. jarvis/jarvis_tools/tool_generator.py +6 -8
  36. jarvis/jarvis_utils/__init__.py +1 -0
  37. jarvis/jarvis_utils/config.py +67 -3
  38. jarvis/jarvis_utils/embedding.py +344 -45
  39. jarvis/jarvis_utils/git_utils.py +9 -1
  40. jarvis/jarvis_utils/input.py +7 -6
  41. jarvis/jarvis_utils/methodology.py +379 -7
  42. jarvis/jarvis_utils/output.py +5 -3
  43. jarvis/jarvis_utils/utils.py +59 -7
  44. {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/METADATA +3 -2
  45. jarvis_ai_assistant-0.1.132.dist-info/RECORD +82 -0
  46. {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/entry_points.txt +2 -0
  47. jarvis/jarvis_codebase/__init__.py +0 -0
  48. jarvis/jarvis_codebase/main.py +0 -1011
  49. jarvis/jarvis_tools/treesitter_analyzer.py +0 -331
  50. jarvis/jarvis_treesitter/README.md +0 -104
  51. jarvis/jarvis_treesitter/__init__.py +0 -20
  52. jarvis/jarvis_treesitter/database.py +0 -258
  53. jarvis/jarvis_treesitter/example.py +0 -115
  54. jarvis/jarvis_treesitter/grammar_builder.py +0 -182
  55. jarvis/jarvis_treesitter/language.py +0 -117
  56. jarvis/jarvis_treesitter/symbol.py +0 -31
  57. jarvis/jarvis_treesitter/tools_usage.md +0 -121
  58. jarvis_ai_assistant-0.1.131.dist-info/RECORD +0 -85
  59. {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/LICENSE +0 -0
  60. {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/WHEEL +0 -0
  61. {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.132.dist-info}/top_level.txt +0 -0
@@ -41,37 +41,20 @@ class ShellTool:
41
41
  """
42
42
  return cmd.replace("'", "'\"'\"'")
43
43
  def execute(self, args: Dict) -> Dict[str, Any]:
44
- """Execute shell command and capture output
45
-
46
- Steps:
47
- 1. Validate and clean input command
48
- 2. Create temporary file for output capture
49
- 3. Execute command with output redirection
50
- 4. Read and process output file
51
- 5. Clean up temporary resources
52
- 6. Return structured results
53
-
54
- Args:
55
- args: Dictionary containing 'command' parameter
56
-
57
- Returns:
58
- Dictionary with:
59
- - success: Boolean indicating command execution status
60
- - stdout: Command output
61
- - stderr: Error message if execution failed
62
- """
63
44
  try:
64
45
  # Get and clean command input
65
46
  command = args["command"].strip()
66
47
 
67
48
  # Generate temporary file name using process ID for uniqueness
49
+ script_file = os.path.join(tempfile.gettempdir(), f"jarvis_shell_{os.getpid()}.sh")
68
50
  output_file = os.path.join(tempfile.gettempdir(), f"jarvis_shell_{os.getpid()}.log")
69
51
 
70
- # Escape special characters in command to prevent injection
71
- escaped_command = self._escape_command(command)
52
+ # Write command to script file
53
+ with open(script_file, 'w', encoding='utf-8') as f:
54
+ f.write(f"#!/bin/bash\n{command}")
72
55
 
73
56
  # Use script command to capture both stdout and stderr
74
- tee_command = f"script -q -c '{escaped_command}' {output_file}"
57
+ tee_command = f"script -q -c 'bash {script_file}' {output_file}"
75
58
 
76
59
  # Execute command and capture return code
77
60
  os.system(tee_command)
@@ -80,7 +63,7 @@ class ShellTool:
80
63
  try:
81
64
  with open(output_file, 'r', encoding='utf-8', errors='ignore') as f:
82
65
  output = f.read()
83
- # Remove header and footer added by script command
66
+ # Remove header and footer added by script command (if any)
84
67
  if output:
85
68
  lines = output.splitlines()
86
69
  if len(lines) > 2:
@@ -88,7 +71,8 @@ class ShellTool:
88
71
  except Exception as e:
89
72
  output = f"读取输出文件失败: {str(e)}"
90
73
  finally:
91
- # Clean up temporary file
74
+ # Clean up temporary files
75
+ Path(script_file).unlink(missing_ok=True)
92
76
  Path(output_file).unlink(missing_ok=True)
93
77
 
94
78
  # Return successful result
@@ -99,7 +83,9 @@ class ShellTool:
99
83
  }
100
84
 
101
85
  except Exception as e:
102
- # Ensure temporary file is cleaned up even if error occurs
86
+ # Ensure temporary files are cleaned up even if error occurs
87
+ if 'script_file' in locals():
88
+ Path(script_file).unlink(missing_ok=True)
103
89
  if 'output_file' in locals():
104
90
  Path(output_file).unlink(missing_ok=True)
105
91
  PrettyOutput.print(str(e), OutputType.ERROR)
@@ -107,4 +93,5 @@ class ShellTool:
107
93
  "success": False,
108
94
  "stdout": "",
109
95
  "stderr": str(e)
110
- }
96
+ }
97
+
@@ -31,7 +31,7 @@ class ShellScriptTool:
31
31
  }
32
32
 
33
33
  # Create temporary script file
34
- script_path = os.path.join(tempfile.gettempdir(), f"jarvis_script_{os.getpid()}.sh")
34
+ script_path = os.path.join(tempfile.gettempdir(), f"jarvis_shell_script_{os.getpid()}.sh")
35
35
  try:
36
36
  with open(script_path, 'w', encoding='utf-8', errors="ignore") as f:
37
37
  f.write(script_content)
@@ -0,0 +1,271 @@
1
+ from typing import Dict, Any
2
+ import os
3
+ import pathlib
4
+
5
+ from jarvis.jarvis_agent import Agent
6
+ from jarvis.jarvis_platform.registry import PlatformRegistry
7
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
8
+
9
+
10
+ class FileAnalyzerTool:
11
+ """
12
+ 单文件分析工具
13
+ 使用agent深入分析单个文件的结构、实现细节和代码质量
14
+ """
15
+
16
+ name = "file_analyzer"
17
+ description = "深入分析单个文件的结构、实现细节和代码质量"
18
+ parameters = {
19
+ "type": "object",
20
+ "properties": {
21
+ "file_path": {
22
+ "type": "string",
23
+ "description": "要分析的文件路径"
24
+ },
25
+ "root_dir": {
26
+ "type": "string",
27
+ "description": "项目根目录路径(可选)",
28
+ "default": "."
29
+ },
30
+ "objective": {
31
+ "type": "string",
32
+ "description": "描述本次文件分析的目标和用途,例如'准备重构该文件'或'理解该文件在项目中的作用'",
33
+ "default": ""
34
+ }
35
+ },
36
+ "required": ["file_path"]
37
+ }
38
+
39
+ def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
40
+ """
41
+ 执行单文件分析工具
42
+
43
+ Args:
44
+ args: 包含参数的字典
45
+
46
+ Returns:
47
+ 包含执行结果的字典
48
+ """
49
+ # 存储原始目录
50
+ original_dir = os.getcwd()
51
+
52
+ try:
53
+ # 解析参数
54
+ file_path = args.get("file_path", "")
55
+ root_dir = args.get("root_dir", ".")
56
+ objective = args.get("objective", "")
57
+
58
+ # 验证参数
59
+ if not file_path:
60
+ return {
61
+ "success": False,
62
+ "stdout": "",
63
+ "stderr": "必须提供文件路径"
64
+ }
65
+
66
+ # 确保文件路径是相对于root_dir的,如果是绝对路径则转换为相对路径
67
+ abs_file_path = os.path.abspath(file_path)
68
+ abs_root_dir = os.path.abspath(root_dir)
69
+
70
+ if abs_file_path.startswith(abs_root_dir):
71
+ rel_file_path = os.path.relpath(abs_file_path, abs_root_dir)
72
+ else:
73
+ rel_file_path = file_path
74
+
75
+ # 获取文件扩展名和文件名
76
+ file_ext = pathlib.Path(file_path).suffix
77
+ file_name = os.path.basename(file_path)
78
+
79
+ # 创建agent的system prompt
80
+ system_prompt = self._create_system_prompt(
81
+ rel_file_path, file_name, file_ext, root_dir, objective
82
+ )
83
+
84
+ # 创建agent的summary prompt
85
+ summary_prompt = self._create_summary_prompt(rel_file_path, file_name)
86
+
87
+ # 切换到根目录
88
+ os.chdir(root_dir)
89
+
90
+ # 检查文件是否存在
91
+ if not os.path.isfile(rel_file_path):
92
+ return {
93
+ "success": False,
94
+ "stdout": "",
95
+ "stderr": f"文件不存在: {rel_file_path}"
96
+ }
97
+
98
+ # 构建使用的工具
99
+ from jarvis.jarvis_tools.registry import ToolRegistry
100
+ tool_registry = ToolRegistry()
101
+ tool_registry.use_tools([
102
+ "execute_shell",
103
+ "read_code",
104
+ "find_symbol",
105
+ "function_analyzer",
106
+ "find_caller"
107
+ ])
108
+
109
+ # 创建并运行agent
110
+ analyzer_agent = Agent(
111
+ system_prompt=system_prompt,
112
+ name=f"FileAnalyzer-{file_name}",
113
+ description=f"分析 {file_name} 文件的结构和实现",
114
+ summary_prompt=summary_prompt,
115
+ platform=PlatformRegistry().get_codegen_platform(),
116
+ output_handler=[tool_registry],
117
+ need_summary=True,
118
+ is_sub_agent=True,
119
+ use_methodology=False,
120
+ record_methodology=False,
121
+ execute_tool_confirm=False,
122
+ auto_complete=True
123
+ )
124
+
125
+ # 运行agent并获取结果
126
+ task_input = f"深入分析文件 {rel_file_path} 的结构、实现细节和代码质量"
127
+ result = analyzer_agent.run(task_input)
128
+
129
+ return {
130
+ "success": True,
131
+ "stdout": result,
132
+ "stderr": ""
133
+ }
134
+
135
+ except Exception as e:
136
+ PrettyOutput.print(str(e), OutputType.ERROR)
137
+ return {
138
+ "success": False,
139
+ "stdout": "",
140
+ "stderr": f"文件分析失败: {str(e)}"
141
+ }
142
+ finally:
143
+ # 恢复原始目录
144
+ os.chdir(original_dir)
145
+
146
+ def _create_system_prompt(self, file_path: str, file_name: str, file_ext: str,
147
+ root_dir: str, objective: str) -> str:
148
+ """
149
+ 创建Agent的system prompt
150
+
151
+ Args:
152
+ file_path: 文件相对路径
153
+ file_name: 文件名
154
+ file_ext: 文件扩展名
155
+ root_dir: 项目根目录
156
+ objective: 分析目标
157
+
158
+ Returns:
159
+ 系统提示文本
160
+ """
161
+ # 根据文件扩展名确定语言
162
+ language_map = {
163
+ '.py': 'Python',
164
+ '.js': 'JavaScript',
165
+ '.ts': 'TypeScript',
166
+ '.java': 'Java',
167
+ '.c': 'C',
168
+ '.cpp': 'C++',
169
+ '.cs': 'C#',
170
+ '.go': 'Go',
171
+ '.rs': 'Rust',
172
+ '.php': 'PHP',
173
+ '.rb': 'Ruby',
174
+ '.swift': 'Swift',
175
+ '.kt': 'Kotlin',
176
+ '.sh': 'Shell',
177
+ '.html': 'HTML',
178
+ '.css': 'CSS',
179
+ '.scss': 'SCSS',
180
+ '.json': 'JSON',
181
+ '.xml': 'XML',
182
+ '.yaml': 'YAML',
183
+ '.md': 'Markdown'
184
+ }
185
+
186
+ language = language_map.get(file_ext, '未知')
187
+ objective_text = f"\n\n## 分析目标\n{objective}" if objective else ""
188
+
189
+ return f"""# 代码文件分析专家
190
+
191
+ ## 任务描述
192
+ 分析文件 `{file_path}` 的内容,专注于分析目标所需的信息,生成有针对性的文件分析报告。{objective_text}
193
+
194
+ ## 文件信息
195
+ - 文件路径: `{file_path}`
196
+ - 编程语言: {language}
197
+ - 项目根目录: `{root_dir}`
198
+
199
+ ## 分析策略
200
+ 1. 首先理解分析目标,确定你需要查找的信息
201
+ 2. 灵活采用适合目标的分析方法,不受预设分析框架的限制
202
+ 3. 专注于与分析目标直接相关的内容,忽略无关部分
203
+ 4. 根据目标需要自行判断分析的深度和广度
204
+
205
+ ## 探索建议
206
+ - 首先读取整个文件内容以获取全局视图
207
+ - 识别与分析目标相关的关键部分
208
+ - 深入探索这些关键部分,提供有针对性的分析
209
+
210
+ ## 执行指令
211
+ - 首先读取整个文件内容:
212
+ ```
213
+ read_code {{
214
+ "files": [{{
215
+ "path": "{file_path}",
216
+ "start_line": 1,
217
+ "end_line": -1
218
+ }}]
219
+ }}
220
+ ```
221
+
222
+ - 分析文件统计信息:
223
+ ```
224
+ wc -l {file_path}
225
+ ```
226
+
227
+ - 分析关键符号和函数:
228
+ ```
229
+ find_symbol {{
230
+ "symbol": "关键符号名称",
231
+ "root_dir": "."
232
+ }}
233
+
234
+ function_analyzer {{
235
+ "function_name": "关键函数名称",
236
+ "file_path": "{file_path}"
237
+ }}
238
+ ```
239
+
240
+ ## 输出要求
241
+ - 直接回应分析目标的关键问题
242
+ - 提供与目标相关的深入洞察
243
+ - 分析内容应直接服务于分析目标
244
+ - 避免与目标无关的冗余信息
245
+ - 使用具体代码路径和示例支持分析结论
246
+ - 提供针对分析目标的具体建议和改进方向"""
247
+
248
+ def _create_summary_prompt(self, file_path: str, file_name: str) -> str:
249
+ """
250
+ 创建Agent的summary prompt
251
+
252
+ Args:
253
+ file_path: 文件路径
254
+ file_name: 文件名
255
+
256
+ Returns:
257
+ 总结提示文本
258
+ """
259
+ return f"""# 文件分析报告: `{file_name}`
260
+
261
+ ## 报告要求
262
+ 生成一份完全以分析目标为导向的文件分析报告。不要遵循固定的报告模板,而是完全根据分析目标来组织内容:
263
+
264
+ - 专注回答分析目标提出的问题
265
+ - 只包含与分析目标直接相关的发现和洞察
266
+ - 完全跳过与分析目标无关的内容,无需做全面分析
267
+ - 分析深度应与目标的具体需求匹配
268
+ - 使用具体的代码片段和实例支持你的观点
269
+ - 以清晰的Markdown格式呈现,简洁明了
270
+
271
+ 在分析中保持灵活性,避免固定思维模式。你的任务不是提供全面的文件概览,而是直接解决分析目标中提出的具体问题。"""
@@ -9,7 +9,7 @@ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
9
9
 
10
10
  class FileOperationTool:
11
11
  name = "file_operation"
12
- description = "用于读写多个文件的操作工具"
12
+ description = "文件批量操作工具,可批量读写多个文件,适用于需要同时处理多个文件的场景(读取配置文件、保存生成内容等),不提供代码分析功能"
13
13
  parameters = {
14
14
  "type": "object",
15
15
  "properties": {
@@ -0,0 +1,213 @@
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_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"查找所有调用 '{function_name}' 函数的代码位置"
117
+ result = caller_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, function_name: 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
+ function_name: 函数名称
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
+ search_pattern = f"\\b{function_name}\\s*\\("
157
+
158
+ return f"""# 函数调用分析专家
159
+
160
+ ## 任务描述
161
+ 查找所有调用 `{function_name}` 函数的代码位置,专注于分析目标所需的信息,生成有针对性的调用分析报告。{objective_text}
162
+
163
+ ## 工作环境
164
+ - 工作目录: `{root_dir}`
165
+ - 文件类型: {file_ext_str if file_ext_str else "所有文件"}
166
+ - 排除目录: {", ".join(exclude_dirs) if exclude_dirs else "无"}
167
+
168
+ ## 分析策略
169
+ 1. 首先理解分析目标,明确需要查找的信息类型
170
+ 2. 使用适当的搜索模式查找函数调用
171
+ 3. 验证搜索结果,确认是对目标函数的真正调用
172
+ 4. 分析调用上下文,了解调用的目的和方式
173
+ 5. 根据分析目标自行确定需要的分析深度和广度
174
+
175
+ ## 执行指令
176
+ - 使用ripgrep(rg)或grep搜索函数调用:
177
+ ```
178
+ rg -n "{search_pattern}" {file_ext_str} {exclude_str}
179
+ ```
180
+ - 使用`read_code`查看上下文分析调用情况
181
+ - 可能需要先找到函数定义以确认正确的函数签名
182
+
183
+ ## 输出要求
184
+ - 直接回应分析目标的关键问题
185
+ - 提供与目标相关的调用信息
186
+ - 分析内容应直接服务于分析目标
187
+ - 避免与目标无关的冗余信息
188
+ - 使用具体代码路径和调用示例支持分析结论
189
+ - 提供针对分析目标的具体见解和建议"""
190
+
191
+ def _create_summary_prompt(self, function_name: str) -> str:
192
+ """
193
+ 创建Agent的summary prompt
194
+
195
+ Args:
196
+ function_name: 函数名称
197
+
198
+ Returns:
199
+ 总结提示文本
200
+ """
201
+ return f"""# 函数 `{function_name}` 调用分析报告
202
+
203
+ ## 报告要求
204
+ 生成一份完全以分析目标为导向的函数调用分析报告。不要遵循固定的报告模板,而是完全根据分析目标来组织内容:
205
+
206
+ - 专注回答分析目标提出的问题
207
+ - 只包含与分析目标直接相关的调用发现和洞察
208
+ - 完全跳过与分析目标无关的内容,无需做全面分析
209
+ - 分析深度应与目标的具体需求匹配
210
+ - 使用具体的代码调用示例支持你的观点
211
+ - 以清晰的Markdown格式呈现,简洁明了
212
+
213
+ 在分析中保持灵活性,避免固定思维模式。你的任务不是提供全面的函数调用概览,而是直接解决分析目标中提出的具体问题。"""