jarvis-ai-assistant 0.1.108__py3-none-any.whl → 0.1.110__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/agent.py +5 -5
- jarvis/jarvis_code_agent/code_agent.py +69 -217
- jarvis/jarvis_code_agent/file_select.py +11 -10
- jarvis/jarvis_code_agent/patch.py +19 -9
- jarvis/jarvis_code_agent/relevant_files.py +1 -162
- jarvis/jarvis_codebase/main.py +55 -60
- jarvis/jarvis_platform/oyi.py +1 -1
- jarvis/jarvis_rag/main.py +194 -268
- jarvis/jarvis_tools/registry.py +10 -9
- jarvis/utils.py +155 -16
- {jarvis_ai_assistant-0.1.108.dist-info → jarvis_ai_assistant-0.1.110.dist-info}/METADATA +12 -3
- {jarvis_ai_assistant-0.1.108.dist-info → jarvis_ai_assistant-0.1.110.dist-info}/RECORD +17 -17
- {jarvis_ai_assistant-0.1.108.dist-info → jarvis_ai_assistant-0.1.110.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.108.dist-info → jarvis_ai_assistant-0.1.110.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.108.dist-info → jarvis_ai_assistant-0.1.110.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.108.dist-info → jarvis_ai_assistant-0.1.110.dist-info}/top_level.txt +0 -0
jarvis/__init__.py
CHANGED
jarvis/agent.py
CHANGED
|
@@ -8,7 +8,7 @@ import yaml
|
|
|
8
8
|
from jarvis.jarvis_platform.base import BasePlatform
|
|
9
9
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
10
10
|
from jarvis.jarvis_tools.registry import ToolRegistry, tool_call_help
|
|
11
|
-
from jarvis.utils import PrettyOutput, OutputType, is_auto_complete, is_need_summary, is_record_methodology, load_methodology, add_agent, delete_current_agent,
|
|
11
|
+
from jarvis.utils import PrettyOutput, OutputType, get_context_token_count, is_auto_complete, is_need_summary, is_record_methodology, load_methodology, add_agent, delete_current_agent, get_max_token_count, get_multiline_input, init_env, is_use_methodology
|
|
12
12
|
import os
|
|
13
13
|
|
|
14
14
|
class Agent:
|
|
@@ -89,7 +89,7 @@ class Agent:
|
|
|
89
89
|
Please describe in concise bullet points, highlighting important information.
|
|
90
90
|
"""
|
|
91
91
|
|
|
92
|
-
self.
|
|
92
|
+
self.max_token_count = max_context_length if max_context_length is not None else get_max_token_count()
|
|
93
93
|
|
|
94
94
|
self.auto_complete = auto_complete if auto_complete is not None else is_auto_complete()
|
|
95
95
|
|
|
@@ -322,16 +322,16 @@ Please continue the task based on the above information.
|
|
|
322
322
|
PrettyOutput.print("Analyzing task...", OutputType.PROGRESS)
|
|
323
323
|
|
|
324
324
|
# 累加对话长度
|
|
325
|
-
self.conversation_length +=
|
|
325
|
+
self.conversation_length += get_context_token_count(self.prompt)
|
|
326
326
|
|
|
327
327
|
# 如果对话历史长度超过限制,在提示中添加提醒
|
|
328
|
-
if self.conversation_length > self.
|
|
328
|
+
if self.conversation_length > self.max_token_count:
|
|
329
329
|
current_response = self._summarize_and_clear_history()
|
|
330
330
|
continue
|
|
331
331
|
else:
|
|
332
332
|
current_response = self._call_model(self.prompt)
|
|
333
333
|
self.prompt = ""
|
|
334
|
-
self.conversation_length +=
|
|
334
|
+
self.conversation_length += get_context_token_count(current_response)
|
|
335
335
|
|
|
336
336
|
for handler in self.output_handler_before_tool:
|
|
337
337
|
self.prompt += handler(current_response)
|
|
@@ -10,9 +10,6 @@ from jarvis.jarvis_tools.registry import ToolRegistry
|
|
|
10
10
|
from jarvis.utils import OutputType, PrettyOutput, get_file_line_count, get_multiline_input, has_uncommitted_changes, init_env, find_git_root
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
13
|
class CodeAgent:
|
|
17
14
|
def __init__(self):
|
|
18
15
|
self.root_dir = os.getcwd()
|
|
@@ -29,229 +26,84 @@ class CodeAgent:
|
|
|
29
26
|
"lsp_find_definition",
|
|
30
27
|
"lsp_prepare_rename",
|
|
31
28
|
"lsp_validate_edit"])
|
|
32
|
-
code_system_prompt = """
|
|
33
|
-
You are a code agent, you are responsible for modifying the code.
|
|
34
|
-
|
|
35
|
-
You should read the code and analyze the code, and then provide a plan for the code modification.
|
|
36
|
-
|
|
37
|
-
## Workflow Steps
|
|
38
|
-
|
|
39
|
-
1. ANALYSIS
|
|
40
|
-
- Use chain of thought to analyze the requirement:
|
|
41
|
-
```
|
|
42
|
-
Thought: Let me understand what the user is asking for...
|
|
43
|
-
Action: Break down the requirement into specific tasks
|
|
44
|
-
Observation: The key tasks are...
|
|
45
|
-
|
|
46
|
-
Thought: Assess task complexity...
|
|
47
|
-
Action: Evaluate each task's scope and dependencies
|
|
48
|
-
Observation: Task complexity analysis shows...
|
|
49
|
-
|
|
50
|
-
Thought: Determine if task splitting is needed...
|
|
51
|
-
Action: Consider using multiple create_code_agent calls
|
|
52
|
-
Observation: Based on complexity, the approach should be...
|
|
53
|
-
|
|
54
|
-
Conclusion:
|
|
55
|
-
1. Task Breakdown: [list of specific tasks]
|
|
56
|
-
2. Complexity Assessment: [simple/complex]
|
|
57
|
-
3. Development Approach: [single/multiple agents]
|
|
58
|
-
4. Task Dependencies: [dependency order]
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
IMPORTANT TASK MANAGEMENT:
|
|
62
|
-
- For complex requirements:
|
|
63
|
-
* Break down into smaller, manageable tasks
|
|
64
|
-
* Use create_code_agent for each sub-task
|
|
65
|
-
* Maintain proper task ordering
|
|
66
|
-
* Ensure integration between sub-tasks
|
|
67
|
-
|
|
68
|
-
Example Task Split:
|
|
69
|
-
```
|
|
70
|
-
1. For complex task "Implement new logging system":
|
|
71
|
-
a. First create_code_agent: "Create basic logging interface"
|
|
72
|
-
b. Second create_code_agent: "Implement file logging backend"
|
|
73
|
-
c. Third create_code_agent: "Add log rotation support"
|
|
74
|
-
|
|
75
|
-
2. Benefits:
|
|
76
|
-
- Focused development for each part
|
|
77
|
-
- Clear progress tracking
|
|
78
|
-
- Easier code review
|
|
79
|
-
- Better error handling
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
2. PLANNING
|
|
83
|
-
- Break down the changes into logical steps using chain of thought:
|
|
84
|
-
```
|
|
85
|
-
Thought: First, let me analyze what needs to be changed...
|
|
86
|
-
Action: Use LSP tools to understand the code structure
|
|
87
|
-
Observation: Found these key components...
|
|
88
|
-
|
|
89
|
-
Thought: Based on the analysis, I need to modify...
|
|
90
|
-
Action: Check dependencies and potential impacts
|
|
91
|
-
Observation: These files will be affected...
|
|
92
|
-
|
|
93
|
-
Thought: Consider previously applied patches...
|
|
94
|
-
Action: Review the changes made so far
|
|
95
|
-
Observation: Previous patches have modified...
|
|
96
|
-
|
|
97
|
-
Thought: The remaining changes should be implemented in this order...
|
|
98
|
-
Plan:
|
|
99
|
-
1. First modify X because... [considering previous changes]
|
|
100
|
-
2. Then update Y to handle... [building on previous patches]
|
|
101
|
-
3. Finally adjust Z to ensure... [maintaining consistency]
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
IMPORTANT PATCH GUIDELINES:
|
|
105
|
-
- Track all previously applied patches
|
|
106
|
-
- Base new patches on the updated code state
|
|
107
|
-
- Consider cumulative effects of patches
|
|
108
|
-
- Verify patch locations against current file state
|
|
109
|
-
- Update line numbers based on previous changes
|
|
110
|
-
- Maintain consistency with earlier modifications
|
|
111
|
-
- If unsure about current state, ask for clarification
|
|
112
|
-
|
|
113
|
-
3. IMPLEMENTATION
|
|
114
|
-
For each file that needs changes:
|
|
115
|
-
a. Code Understanding:
|
|
116
|
-
- Use LSP tools to verify current implementation:
|
|
117
|
-
* lsp_get_document_symbols to see current structure
|
|
118
|
-
* lsp_find_definition to confirm current definitions
|
|
119
|
-
* lsp_find_references to trace current usages
|
|
120
|
-
- Consider effects of previous patches
|
|
121
|
-
- Understand current code state
|
|
122
|
-
- Verify patch locations are still valid
|
|
123
|
-
|
|
124
|
-
b. Change Planning:
|
|
125
|
-
- Plan changes based on current code state
|
|
126
|
-
- Account for previous modifications
|
|
127
|
-
- Ensure compatibility with applied patches
|
|
128
|
-
- Update line numbers if needed
|
|
129
|
-
- Document dependencies on previous changes
|
|
130
|
-
|
|
131
|
-
c. Implementation:
|
|
132
|
-
- Write patches for current code state
|
|
133
|
-
- Reference previous patch effects
|
|
134
|
-
- Maintain consistency with earlier changes
|
|
135
|
-
- Verify patch locations are accurate
|
|
136
|
-
- Consider cumulative impact
|
|
137
|
-
|
|
138
|
-
d. Verification:
|
|
139
|
-
- Verify against current code state
|
|
140
|
-
- Test compatibility with previous patches
|
|
141
|
-
- Check for patch sequence issues
|
|
142
|
-
- Validate cumulative changes
|
|
143
|
-
|
|
144
|
-
## File Reading Guidelines
|
|
145
|
-
|
|
146
|
-
1. For Large Files (>200 lines):
|
|
147
|
-
- Do NOT read the entire file at once using 'read_code'
|
|
148
|
-
- First use 'execute_shell' with grep/find to locate relevant sections
|
|
149
|
-
- Then use 'read_code' with specific line ranges to read only necessary portions
|
|
150
|
-
- Example:
|
|
151
|
-
* Use: execute_shell("grep -n 'function_name' path/to/file")
|
|
152
|
-
* Then: read_code("path/to/file", start_line=found_line-10, end_line=found_line+20)
|
|
153
|
-
|
|
154
|
-
2. For Small Files:
|
|
155
|
-
- Can read entire file using 'read_code' directly
|
|
29
|
+
code_system_prompt = """You are a code agent responsible for modifying code. You will analyze code and create patches while following these guidelines:
|
|
156
30
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
1. Basic Format:
|
|
160
|
-
<PATCH>
|
|
161
|
-
> /path/to/file start_line,end_line
|
|
162
|
-
new_content_line1
|
|
163
|
-
new_content_line2
|
|
164
|
-
</PATCH>
|
|
165
|
-
|
|
166
|
-
2. Rules:
|
|
167
|
-
- Each <PATCH> block MUST contain exactly ONE patch for ONE location
|
|
168
|
-
- Multiple changes to different locations require separate <PATCH> blocks
|
|
169
|
-
- Line Numbers Behavior:
|
|
170
|
-
* start_line (first number): This line WILL be replaced
|
|
171
|
-
* end_line (second number): This line will NOT be replaced
|
|
172
|
-
* The patch replaces content from start_line (inclusive) to end_line (exclusive)
|
|
173
|
-
- Use absolute paths relative to the project root
|
|
174
|
-
- Maintain consistent indentation
|
|
175
|
-
- Include enough context for precise location
|
|
176
|
-
|
|
177
|
-
3. Multiple Changes Example:
|
|
178
|
-
Before:
|
|
179
|
-
```
|
|
180
|
-
Line 0: first line
|
|
181
|
-
Line 1: second line
|
|
182
|
-
Line 2: third line
|
|
183
|
-
Line 3: fourth line
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
For multiple changes, use separate patches:
|
|
187
|
-
```
|
|
31
|
+
# Patch Format
|
|
188
32
|
<PATCH>
|
|
189
|
-
> /path/
|
|
190
|
-
|
|
33
|
+
> /path/file start,end
|
|
34
|
+
new_content
|
|
191
35
|
</PATCH>
|
|
192
36
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
37
|
+
Key Rules:
|
|
38
|
+
• One modification per patch block
|
|
39
|
+
• Line numbers are based on original file
|
|
40
|
+
• Start line is included, end line is excluded
|
|
41
|
+
• Same start/end number: insert before that line
|
|
42
|
+
• Start=0, end=0: create new file with content
|
|
43
|
+
|
|
44
|
+
# Code Compatibility
|
|
45
|
+
1. System Integration
|
|
46
|
+
• Maintain existing API contracts
|
|
47
|
+
• Preserve function signatures
|
|
48
|
+
• Keep data structures compatible
|
|
49
|
+
• Honor return types and exceptions
|
|
50
|
+
|
|
51
|
+
2. Style Consistency
|
|
52
|
+
• Match naming conventions
|
|
53
|
+
• Follow indentation patterns
|
|
54
|
+
• Use existing import style
|
|
55
|
+
• Keep comment format
|
|
56
|
+
|
|
57
|
+
3. Pattern Alignment
|
|
58
|
+
• Use similar error handling
|
|
59
|
+
• Follow existing design patterns
|
|
60
|
+
• Match logging approach
|
|
61
|
+
• Keep configuration style
|
|
62
|
+
|
|
63
|
+
# Development Process
|
|
64
|
+
1. ANALYZE
|
|
65
|
+
• Break down requirements
|
|
66
|
+
• Assess task complexity
|
|
67
|
+
• Determine if subtasks needed
|
|
68
|
+
|
|
69
|
+
2. ASSESS
|
|
70
|
+
• Map dependencies
|
|
71
|
+
• Check compatibility impact
|
|
72
|
+
• Identify integration points
|
|
73
|
+
|
|
74
|
+
3. IMPLEMENT
|
|
75
|
+
• Follow existing patterns
|
|
76
|
+
• Make minimal changes
|
|
77
|
+
• Verify integrations
|
|
78
|
+
|
|
79
|
+
# File Handling
|
|
80
|
+
Large Files (>200 lines):
|
|
81
|
+
1. Use grep/find to locate relevant sections
|
|
82
|
+
2. Read specific ranges with read_code
|
|
83
|
+
3. Apply targeted changes
|
|
84
|
+
|
|
85
|
+
# Available Tools
|
|
86
|
+
Primary:
|
|
87
|
+
• LSP tools for code analysis
|
|
88
|
+
• read_code with line ranges
|
|
89
|
+
• execute_shell for searches
|
|
90
|
+
• ask_user when unclear
|
|
91
|
+
|
|
92
|
+
# Quality Requirements
|
|
93
|
+
Code Changes Must:
|
|
94
|
+
✓ Preserve interfaces
|
|
95
|
+
✓ Match existing style
|
|
96
|
+
✓ Handle errors consistently
|
|
97
|
+
✓ Maintain documentation
|
|
98
|
+
✓ Keep test coverage
|
|
99
|
+
✓ Follow project patterns"""
|
|
249
100
|
self.agent = Agent(system_prompt=code_system_prompt,
|
|
250
101
|
name="CodeAgent",
|
|
251
102
|
auto_complete=False,
|
|
252
103
|
is_sub_agent=False,
|
|
104
|
+
use_methodology=False,
|
|
253
105
|
tool_registry=tool_registry,
|
|
254
|
-
platform=PlatformRegistry().
|
|
106
|
+
platform=PlatformRegistry().get_thinking_platform(),
|
|
255
107
|
record_methodology=False,
|
|
256
108
|
output_handler_after_tool=[apply_patch],
|
|
257
109
|
need_summary=False)
|
|
@@ -137,16 +137,17 @@ def select_files(related_files: List[str], root_dir: str) -> List[str]:
|
|
|
137
137
|
|
|
138
138
|
PrettyOutput.print(output, OutputType.INFO, lang="markdown")
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
140
|
+
if len(related_files) > 0:
|
|
141
|
+
# Ask the user if they need to adjust the file list
|
|
142
|
+
if user_confirm("Do you need to adjust the file list?", False):
|
|
143
|
+
# Let the user select files
|
|
144
|
+
numbers = get_single_line_input("Please enter the file numbers to include (support: 1,3-6 format, press Enter to keep the current selection)").strip()
|
|
145
|
+
if numbers:
|
|
146
|
+
selected_indices = _parse_file_selection(numbers, len(related_files))
|
|
147
|
+
if selected_indices:
|
|
148
|
+
selected_files = [related_files[i] for i in selected_indices]
|
|
149
|
+
else:
|
|
150
|
+
PrettyOutput.print("No valid files selected, keep the current selection", OutputType.WARNING)
|
|
150
151
|
|
|
151
152
|
# Ask if they need to supplement files
|
|
152
153
|
if user_confirm("Do you need to supplement other files?", False):
|
|
@@ -62,15 +62,6 @@ def apply_patch(output_str: str)->str:
|
|
|
62
62
|
|
|
63
63
|
for filepath, patch_info in patches.items():
|
|
64
64
|
try:
|
|
65
|
-
# Check if file exists
|
|
66
|
-
if not os.path.exists(filepath):
|
|
67
|
-
PrettyOutput.print(f"File not found: {filepath}", OutputType.WARNING)
|
|
68
|
-
continue
|
|
69
|
-
|
|
70
|
-
# Read original file content
|
|
71
|
-
lines = open(filepath, 'r', encoding='utf-8').readlines()
|
|
72
|
-
|
|
73
|
-
# Apply patch
|
|
74
65
|
for patch in patch_info:
|
|
75
66
|
start_line = patch['start_line']
|
|
76
67
|
end_line = patch['end_line']
|
|
@@ -78,6 +69,25 @@ def apply_patch(output_str: str)->str:
|
|
|
78
69
|
|
|
79
70
|
if new_content and new_content[-1] and new_content[-1][-1] != '\n':
|
|
80
71
|
new_content[-1] += '\n'
|
|
72
|
+
|
|
73
|
+
# Handle file creation when start=end=0
|
|
74
|
+
if start_line == 0 and end_line == 0:
|
|
75
|
+
# Create directory if it doesn't exist
|
|
76
|
+
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
|
77
|
+
# Write new file
|
|
78
|
+
with open(filepath, 'w', encoding='utf-8') as f:
|
|
79
|
+
f.writelines(new_content)
|
|
80
|
+
PrettyOutput.print(f"Created new file {filepath} successfully\n", OutputType.SUCCESS)
|
|
81
|
+
continue
|
|
82
|
+
|
|
83
|
+
# Regular patch logic for existing files
|
|
84
|
+
if not os.path.exists(filepath):
|
|
85
|
+
PrettyOutput.print(f"File not found: {filepath}", OutputType.WARNING)
|
|
86
|
+
continue
|
|
87
|
+
|
|
88
|
+
# Read original file content
|
|
89
|
+
lines = open(filepath, 'r', encoding='utf-8').readlines()
|
|
90
|
+
|
|
81
91
|
# Validate line numbers
|
|
82
92
|
if start_line < 0 or end_line > len(lines) + 1 or start_line > end_line:
|
|
83
93
|
PrettyOutput.print(f"Invalid line range [{start_line}, {end_line}) for file: {filepath}", OutputType.WARNING)
|
|
@@ -11,165 +11,6 @@ from jarvis.jarvis_tools.registry import ToolRegistry
|
|
|
11
11
|
from jarvis.utils import OutputType, PrettyOutput, is_disable_codebase
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
def find_relevant_files_from_agent(user_input: str, files_from_codebase: List[str]) -> List[str]:
|
|
15
|
-
find_file_tool_registry = ToolRegistry()
|
|
16
|
-
find_file_tool_registry.use_tools(["read_code",
|
|
17
|
-
"execute_shell",
|
|
18
|
-
"lsp_get_document_symbols",
|
|
19
|
-
"lsp_get_diagnostics",
|
|
20
|
-
"lsp_find_references",
|
|
21
|
-
"lsp_find_definition",
|
|
22
|
-
"lsp_prepare_rename",
|
|
23
|
-
"lsp_validate_edit"])
|
|
24
|
-
find_file_agent = Agent(
|
|
25
|
-
system_prompt="""You are a file agent, you are responsible for finding files related to the user's requirement.
|
|
26
|
-
|
|
27
|
-
THINKING PROCESS:
|
|
28
|
-
1. Initial File Verification
|
|
29
|
-
```
|
|
30
|
-
Thought: Let me examine the suggested files...
|
|
31
|
-
Action: For each suggested file:
|
|
32
|
-
- Use read_code to check content
|
|
33
|
-
- Use LSP tools to analyze structure
|
|
34
|
-
Observation: Found that...
|
|
35
|
-
|
|
36
|
-
Thought: Evaluate actual relevance...
|
|
37
|
-
Action: For each file:
|
|
38
|
-
- Check direct relationship to requirement
|
|
39
|
-
- Verify functionality matches
|
|
40
|
-
- Look for clear evidence of relevance
|
|
41
|
-
Observation: After analysis:
|
|
42
|
-
- Relevant files: [list with reasons]
|
|
43
|
-
- Removed files: [list with reasons]
|
|
44
|
-
|
|
45
|
-
Thought: Verify removal decisions...
|
|
46
|
-
Action: Double-check each removed file
|
|
47
|
-
Observation: Removal justification:
|
|
48
|
-
- File X: [specific reason for removal]
|
|
49
|
-
- File Y: [specific reason for removal]
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
2. Additional File Search
|
|
53
|
-
```
|
|
54
|
-
Thought: Plan search strategy for missing aspects...
|
|
55
|
-
Action: Use combination of tools:
|
|
56
|
-
- git grep for key terms
|
|
57
|
-
- LSP tools for references
|
|
58
|
-
- Dependency analysis
|
|
59
|
-
Observation: Found additional files...
|
|
60
|
-
|
|
61
|
-
Thought: Validate new files...
|
|
62
|
-
Action: For each new file:
|
|
63
|
-
- Verify direct relevance
|
|
64
|
-
- Check for false positives
|
|
65
|
-
- Document clear evidence
|
|
66
|
-
Observation: After validation:
|
|
67
|
-
- Confirmed relevant: [list with evidence]
|
|
68
|
-
- Excluded: [list with reasons]
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
3. Comprehensive Analysis
|
|
72
|
-
```
|
|
73
|
-
Thought: Final relevance check...
|
|
74
|
-
Action: For each remaining file:
|
|
75
|
-
- Verify essential to requirement
|
|
76
|
-
- Check for indirect inclusions
|
|
77
|
-
- Validate necessity
|
|
78
|
-
Observation: Final cleanup:
|
|
79
|
-
- Core files: [list with roles]
|
|
80
|
-
- Removed borderline cases: [list with reasons]
|
|
81
|
-
|
|
82
|
-
Thought: Ensure minimal complete set...
|
|
83
|
-
Action: Review final file list
|
|
84
|
-
Observation: Confirmed each file is:
|
|
85
|
-
- Directly relevant
|
|
86
|
-
- Essential for requirement
|
|
87
|
-
- Supported by evidence
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
FILE READING GUIDELINES:
|
|
91
|
-
1. For Large Files (>200 lines):
|
|
92
|
-
```
|
|
93
|
-
Thought: This file is large, need targeted reading...
|
|
94
|
-
Action:
|
|
95
|
-
- First: execute_shell("grep -n 'key_term' path/to/file")
|
|
96
|
-
- Then: read_code("path/to/file", start_line=x-10, end_line=x+20)
|
|
97
|
-
Observation: Relevance analysis:
|
|
98
|
-
- Relevant sections: [details]
|
|
99
|
-
- Irrelevant sections: [reasons to ignore]
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
2. For Small Files:
|
|
103
|
-
```
|
|
104
|
-
Thought: This is a small file, can read entirely...
|
|
105
|
-
Action: read_code("path/to/file")
|
|
106
|
-
Observation: Relevance analysis:
|
|
107
|
-
- Key evidence: [details]
|
|
108
|
-
- Irrelevant aspects: [what to ignore]
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
VERIFICATION RULES:
|
|
112
|
-
- Remove files without clear relevance evidence
|
|
113
|
-
- Exclude files with only tangential relationships
|
|
114
|
-
- Delete files that only contain imports/references
|
|
115
|
-
- Remove files if relevance is uncertain
|
|
116
|
-
- Document specific reasons for each removal
|
|
117
|
-
- Keep only files essential to requirement
|
|
118
|
-
- Maintain minimal complete set
|
|
119
|
-
|
|
120
|
-
OUTPUT FORMAT:
|
|
121
|
-
<FILE_PATH>
|
|
122
|
-
- file_path1 # KEEP: [specific evidence of relevance]
|
|
123
|
-
- file_path2 # KEEP: [clear relationship to requirement]
|
|
124
|
-
</FILE_PATH>
|
|
125
|
-
""",
|
|
126
|
-
name="FindFileAgent",
|
|
127
|
-
is_sub_agent=True,
|
|
128
|
-
tool_registry=find_file_tool_registry,
|
|
129
|
-
platform=PlatformRegistry().get_normal_platform(),
|
|
130
|
-
auto_complete=True,
|
|
131
|
-
summary_prompt="""Please provide only the verified essential files with evidence:
|
|
132
|
-
<FILE_PATH>
|
|
133
|
-
- file_path1 # KEEP: [concrete evidence of necessity]
|
|
134
|
-
- file_path2 # KEEP: [specific relevance proof]
|
|
135
|
-
</FILE_PATH>
|
|
136
|
-
""")
|
|
137
|
-
|
|
138
|
-
prompt = f"Find files related to: '{user_input}'\n"
|
|
139
|
-
if files_from_codebase:
|
|
140
|
-
prompt += f"""
|
|
141
|
-
Potentially related files: {files_from_codebase}
|
|
142
|
-
|
|
143
|
-
ANALYSIS REQUIRED:
|
|
144
|
-
1. Verify each suggested file:
|
|
145
|
-
- Document relevance evidence
|
|
146
|
-
- Identify actual relationships
|
|
147
|
-
- Note any missing aspects
|
|
148
|
-
|
|
149
|
-
2. Search for additional files:
|
|
150
|
-
- Fill coverage gaps
|
|
151
|
-
- Find related components
|
|
152
|
-
- Locate test files
|
|
153
|
-
|
|
154
|
-
3. Provide reasoning:
|
|
155
|
-
- Explain why each file is included
|
|
156
|
-
- Document verification process
|
|
157
|
-
- Note any uncertainties
|
|
158
|
-
"""
|
|
159
|
-
output = find_file_agent.run(prompt)
|
|
160
|
-
|
|
161
|
-
rsp_from_agent = re.findall(r'<FILE_PATH>(.*?)</FILE_PATH>', output, re.DOTALL)
|
|
162
|
-
files_from_agent = []
|
|
163
|
-
if rsp_from_agent:
|
|
164
|
-
try:
|
|
165
|
-
files_from_agent = yaml.safe_load(rsp_from_agent[0])
|
|
166
|
-
except Exception as e:
|
|
167
|
-
files_from_agent = []
|
|
168
|
-
else:
|
|
169
|
-
files_from_agent = []
|
|
170
|
-
return files_from_agent
|
|
171
|
-
|
|
172
|
-
|
|
173
14
|
def find_relevant_files(user_input: str, root_dir: str) -> List[str]:
|
|
174
15
|
try:
|
|
175
16
|
files_from_codebase = []
|
|
@@ -180,9 +21,7 @@ def find_relevant_files(user_input: str, root_dir: str) -> List[str]:
|
|
|
180
21
|
|
|
181
22
|
PrettyOutput.print("Find files by agent...", OutputType.INFO)
|
|
182
23
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
selected_files = select_files(files_from_agent, os.getcwd())
|
|
24
|
+
selected_files = select_files(files_from_codebase, os.getcwd())
|
|
186
25
|
return selected_files
|
|
187
26
|
except Exception as e:
|
|
188
27
|
return []
|