jarvis-ai-assistant 0.1.115__py3-none-any.whl → 0.1.117__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 → jarvis_agent/__init__.py} +122 -203
- jarvis/jarvis_agent/output_handler.py +23 -0
- jarvis/jarvis_code_agent/code_agent.py +113 -100
- jarvis/jarvis_code_agent/file_select.py +28 -7
- jarvis/jarvis_code_agent/patch.py +80 -2
- jarvis/jarvis_code_agent/relevant_files.py +82 -42
- jarvis/jarvis_codebase/main.py +53 -25
- jarvis/jarvis_dev/main.py +719 -547
- jarvis/jarvis_lsp/cpp.py +1 -1
- jarvis/jarvis_lsp/go.py +1 -1
- jarvis/jarvis_lsp/registry.py +1 -1
- jarvis/jarvis_lsp/rust.py +1 -1
- jarvis/jarvis_multi_agent/__init__.py +170 -0
- jarvis/jarvis_platform/ai8.py +2 -2
- jarvis/jarvis_platform/base.py +14 -4
- jarvis/jarvis_platform/kimi.py +2 -2
- jarvis/jarvis_platform/ollama.py +1 -1
- jarvis/jarvis_platform/openai.py +1 -1
- jarvis/jarvis_platform/oyi.py +1 -1
- jarvis/jarvis_platform/registry.py +1 -1
- jarvis/jarvis_platform_manager/main.py +422 -6
- jarvis/jarvis_platform_manager/openai_test.py +139 -0
- jarvis/jarvis_rag/main.py +57 -20
- jarvis/jarvis_smart_shell/main.py +55 -29
- jarvis/jarvis_tools/ask_codebase.py +1 -1
- jarvis/jarvis_tools/ask_user.py +1 -1
- jarvis/jarvis_tools/chdir.py +1 -1
- jarvis/jarvis_tools/code_review.py +3 -3
- jarvis/jarvis_tools/create_code_agent.py +1 -1
- jarvis/jarvis_tools/create_sub_agent.py +2 -2
- jarvis/jarvis_tools/execute_shell.py +1 -1
- jarvis/jarvis_tools/file_operation.py +16 -14
- jarvis/jarvis_tools/git_commiter.py +2 -2
- jarvis/jarvis_tools/methodology.py +1 -1
- jarvis/jarvis_tools/rag.py +1 -1
- jarvis/jarvis_tools/read_code.py +19 -8
- jarvis/jarvis_tools/read_webpage.py +1 -1
- jarvis/jarvis_tools/registry.py +157 -31
- jarvis/jarvis_tools/search.py +1 -1
- jarvis/jarvis_tools/select_code_files.py +1 -1
- jarvis/{utils.py → jarvis_utils/__init__.py} +69 -53
- {jarvis_ai_assistant-0.1.115.dist-info → jarvis_ai_assistant-0.1.117.dist-info}/METADATA +1 -1
- jarvis_ai_assistant-0.1.117.dist-info/RECORD +65 -0
- {jarvis_ai_assistant-0.1.115.dist-info → jarvis_ai_assistant-0.1.117.dist-info}/WHEEL +1 -1
- {jarvis_ai_assistant-0.1.115.dist-info → jarvis_ai_assistant-0.1.117.dist-info}/entry_points.txt +1 -1
- jarvis/multi_agent.py +0 -76
- jarvis/utils/date_utils.py +0 -19
- jarvis_ai_assistant-0.1.115.dist-info/RECORD +0 -64
- {jarvis_ai_assistant-0.1.115.dist-info → jarvis_ai_assistant-0.1.117.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.115.dist-info → jarvis_ai_assistant-0.1.117.dist-info}/top_level.txt +0 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from typing import Dict, List
|
|
3
3
|
|
|
4
|
-
from jarvis.
|
|
5
|
-
from jarvis.jarvis_code_agent.
|
|
4
|
+
from jarvis.jarvis_agent import Agent
|
|
5
|
+
from jarvis.jarvis_code_agent.file_select import file_input_handler
|
|
6
|
+
from jarvis.jarvis_code_agent.patch import PatchOutputHandler
|
|
6
7
|
from jarvis.jarvis_code_agent.relevant_files import find_relevant_information
|
|
7
8
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
8
9
|
from jarvis.jarvis_tools.git_commiter import GitCommitTool
|
|
9
10
|
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
10
|
-
from jarvis.
|
|
11
|
+
from jarvis.jarvis_tools.read_code import ReadCodeTool
|
|
12
|
+
from jarvis.jarvis_utils import OutputType, PrettyOutput, get_multiline_input, has_uncommitted_changes, init_env, find_git_root
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
class CodeAgent:
|
|
@@ -26,113 +28,120 @@ class CodeAgent:
|
|
|
26
28
|
"lsp_find_definition",
|
|
27
29
|
"lsp_prepare_rename",
|
|
28
30
|
"lsp_validate_edit"])
|
|
29
|
-
code_system_prompt = """
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
31
|
+
code_system_prompt = """
|
|
32
|
+
# 🤖 Role Definition
|
|
33
|
+
You are a code agent specialized in code modification. Your primary responsibility is to understand existing code thoroughly and ensure system compatibility.
|
|
34
|
+
|
|
35
|
+
# 🎯 Core Responsibilities
|
|
36
|
+
- Analyze and understand existing code
|
|
37
|
+
- Maintain system compatibility
|
|
38
|
+
- Generate high-quality code changes
|
|
39
|
+
- Ensure complete implementation
|
|
40
|
+
- Follow project conventions
|
|
41
|
+
|
|
42
|
+
# 🔄 Development Workflow
|
|
43
|
+
1. Code Analysis
|
|
44
|
+
- Read and understand existing code thoroughly
|
|
45
|
+
- Map out affected components
|
|
46
|
+
- Identify patterns and conventions
|
|
47
|
+
- Document dependencies
|
|
48
|
+
|
|
49
|
+
2. Change Planning
|
|
50
|
+
- Evaluate impact on system
|
|
51
|
+
- Verify API compatibility
|
|
52
|
+
- Consider side effects
|
|
53
|
+
- Plan minimal changes
|
|
54
|
+
|
|
55
|
+
3. Implementation
|
|
56
|
+
- Follow existing patterns exactly
|
|
57
|
+
- Maintain backward compatibility
|
|
58
|
+
- Complete implementation fully
|
|
59
|
+
- Document all changes
|
|
60
|
+
|
|
61
|
+
# 📋 Code Quality Requirements
|
|
62
|
+
## Implementation Completeness
|
|
63
|
+
- NO TODOs or placeholders
|
|
64
|
+
- NO unfinished functions
|
|
65
|
+
- NO stub implementations
|
|
66
|
+
- Full error handling
|
|
67
|
+
- Complete edge cases
|
|
68
|
+
|
|
69
|
+
## Documentation Standards
|
|
70
|
+
- Function docstrings
|
|
71
|
+
- Parameter documentation
|
|
72
|
+
- Return value specifications
|
|
73
|
+
- Exception documentation
|
|
74
|
+
- Complex logic explanation
|
|
75
|
+
|
|
76
|
+
## System Compatibility
|
|
77
|
+
- Preserve API contracts
|
|
78
|
+
- Maintain function signatures
|
|
79
|
+
- Keep data structure compatibility
|
|
80
|
+
- Follow error handling patterns
|
|
81
|
+
|
|
82
|
+
## Style Guidelines
|
|
83
|
+
- Match naming conventions
|
|
84
|
+
- Follow code organization
|
|
85
|
+
- Use consistent import style
|
|
86
|
+
- Maintain comment patterns
|
|
87
|
+
|
|
88
|
+
# 🛠️ Available Tools
|
|
89
|
+
## Primary Tools
|
|
90
|
+
- `read_code`: MUST use to understand existing code
|
|
91
|
+
- `lsp_*`: Code analysis tools
|
|
92
|
+
- `execute_shell`: For code searches
|
|
93
|
+
- `ask_user`: When clarification needed
|
|
94
|
+
|
|
95
|
+
## LSP Tools
|
|
96
|
+
- `lsp_get_document_symbols`
|
|
97
|
+
- `lsp_get_diagnostics`
|
|
98
|
+
- `lsp_find_references`
|
|
99
|
+
- `lsp_find_definition`
|
|
100
|
+
- `lsp_prepare_rename`
|
|
101
|
+
- `lsp_validate_edit`
|
|
102
|
+
|
|
103
|
+
# 📝 File Modification Rules
|
|
104
|
+
- One modification per patch block
|
|
105
|
+
- Line numbers based on original file
|
|
106
|
+
- Start line included, end line excluded
|
|
107
|
+
- Same start/end: insert before line
|
|
108
|
+
- Start=0, end=0: create new file
|
|
109
|
+
|
|
110
|
+
# 📚 Large File Handling (>200 lines)
|
|
111
|
+
1. Use grep/find for section location
|
|
107
112
|
2. Read specific ranges with read_code
|
|
108
113
|
3. Apply targeted changes
|
|
109
114
|
|
|
110
|
-
#
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
115
|
+
# ❗ Critical Rules
|
|
116
|
+
1. MUST read code before changes
|
|
117
|
+
2. MUST preserve interfaces
|
|
118
|
+
3. MUST follow existing patterns
|
|
119
|
+
4. MUST complete implementation
|
|
120
|
+
5. MUST document thoroughly
|
|
121
|
+
6. MUST handle errors
|
|
122
|
+
7. NO TODOs or stubs
|
|
123
|
+
8. ONE modification per patch
|
|
124
|
+
|
|
125
|
+
# ✅ Quality Checklist
|
|
126
|
+
Before submitting changes, verify:
|
|
127
|
+
□ Based on thorough code reading
|
|
128
|
+
□ Preserves all interfaces
|
|
129
|
+
□ Matches existing style
|
|
130
|
+
□ Handles all errors
|
|
131
|
+
□ Complete documentation
|
|
132
|
+
□ Follows project patterns
|
|
133
|
+
□ No TODOs or stubs
|
|
134
|
+
□ One change per patch
|
|
135
|
+
"""
|
|
127
136
|
self.agent = Agent(system_prompt=code_system_prompt,
|
|
128
137
|
name="CodeAgent",
|
|
129
138
|
auto_complete=False,
|
|
130
139
|
is_sub_agent=False,
|
|
131
140
|
use_methodology=False,
|
|
132
|
-
|
|
141
|
+
output_handler=[tool_registry, PatchOutputHandler()],
|
|
133
142
|
platform=PlatformRegistry().get_codegen_platform(),
|
|
134
143
|
record_methodology=False,
|
|
135
|
-
|
|
144
|
+
input_handler=[file_input_handler],
|
|
136
145
|
need_summary=False)
|
|
137
146
|
|
|
138
147
|
|
|
@@ -160,6 +169,10 @@ Every Change Must:
|
|
|
160
169
|
# Then try to add file contents
|
|
161
170
|
for file in files:
|
|
162
171
|
prompt_parts.append(f'''- {file['file']} ({file['reason']})''')
|
|
172
|
+
|
|
173
|
+
result = ReadCodeTool().execute({"files": [{"file": file["file"], "reason": file["reason"]} for file in files]})
|
|
174
|
+
if result["success"]:
|
|
175
|
+
prompt_parts.append(result["stdout"])
|
|
163
176
|
|
|
164
177
|
return "\n".join(prompt_parts)
|
|
165
178
|
|
|
@@ -3,7 +3,8 @@ import re
|
|
|
3
3
|
from typing import Dict, List
|
|
4
4
|
from prompt_toolkit import PromptSession
|
|
5
5
|
from prompt_toolkit.completion import Completer, Completion
|
|
6
|
-
from jarvis.
|
|
6
|
+
from jarvis.jarvis_tools.read_code import ReadCodeTool
|
|
7
|
+
from jarvis.jarvis_utils import OutputType, PrettyOutput, get_single_line_input, user_confirm
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
def _parse_file_selection(input_str: str, max_index: int) -> List[int]:
|
|
@@ -135,6 +136,9 @@ def select_files(related_files: List[Dict[str, str]], root_dir: str) -> List[Dic
|
|
|
135
136
|
for i, file in enumerate(related_files, 1):
|
|
136
137
|
output += f"[{i}] {file['file']} ({file['reason']})\n"
|
|
137
138
|
|
|
139
|
+
# Filter out files that do not exist
|
|
140
|
+
related_files = [f for f in related_files if os.path.isfile(os.path.join(root_dir, f["file"]))]
|
|
141
|
+
|
|
138
142
|
PrettyOutput.print(output, OutputType.INFO, lang="markdown")
|
|
139
143
|
|
|
140
144
|
if len(related_files) > 0:
|
|
@@ -175,9 +179,10 @@ def select_files(related_files: List[Dict[str, str]], root_dir: str) -> List[Dic
|
|
|
175
179
|
continue
|
|
176
180
|
|
|
177
181
|
# Display matching files
|
|
178
|
-
|
|
182
|
+
tips = "找到以下匹配的文件:"
|
|
179
183
|
for i, path in enumerate(matches, 1):
|
|
180
|
-
|
|
184
|
+
tips += f"\n[{i}] {path}"
|
|
185
|
+
PrettyOutput.print(tips, OutputType.INFO)
|
|
181
186
|
|
|
182
187
|
# Let the user select
|
|
183
188
|
numbers = get_single_line_input("请选择要添加的文件编号(支持: 1,3-6格式, 按回车选择所有)").strip()
|
|
@@ -192,16 +197,32 @@ def select_files(related_files: List[Dict[str, str]], root_dir: str) -> List[Dic
|
|
|
192
197
|
paths_to_add = [file_path]
|
|
193
198
|
|
|
194
199
|
# Add selected files
|
|
200
|
+
tips = "添加以下文件:"
|
|
195
201
|
for path in paths_to_add:
|
|
196
202
|
full_path = os.path.join(root_dir, path)
|
|
197
203
|
if not os.path.isfile(full_path):
|
|
198
|
-
|
|
204
|
+
tips += f"\n文件不存在: {path}"
|
|
199
205
|
continue
|
|
200
206
|
|
|
201
207
|
try:
|
|
202
208
|
selected_files.append({"file": path, "reason": "User Added"})
|
|
203
|
-
|
|
209
|
+
tips += f"\n文件已添加: {path}"
|
|
204
210
|
except Exception as e:
|
|
205
|
-
|
|
211
|
+
tips += f"\n读取文件失败: {str(e)}"
|
|
212
|
+
selected_files = [f for f in selected_files if os.path.isfile(os.path.join(root_dir, f["file"]))]
|
|
213
|
+
PrettyOutput.print(tips, OutputType.INFO)
|
|
214
|
+
return selected_files
|
|
215
|
+
|
|
216
|
+
def file_input_handler(user_input: str) -> str:
|
|
217
|
+
prompt = user_input
|
|
218
|
+
files = []
|
|
219
|
+
sm = re.findall(r'`(.+?)`', user_input)
|
|
220
|
+
if sm:
|
|
221
|
+
for s in sm:
|
|
222
|
+
if os.path.isfile(s[0]):
|
|
223
|
+
files.append(s[0])
|
|
224
|
+
result = ReadCodeTool().execute({"files": files})
|
|
225
|
+
if result["success"]:
|
|
226
|
+
return result["stdout"] + "\n" + prompt
|
|
206
227
|
|
|
207
|
-
return
|
|
228
|
+
return prompt
|
|
@@ -1,8 +1,86 @@
|
|
|
1
1
|
import re
|
|
2
|
-
from typing import Dict, Any, List
|
|
2
|
+
from typing import Dict, Any, List, Tuple
|
|
3
3
|
import os
|
|
4
|
+
from jarvis.jarvis_agent.output_handler import OutputHandler
|
|
4
5
|
from jarvis.jarvis_tools.git_commiter import GitCommitTool
|
|
5
|
-
from jarvis.
|
|
6
|
+
from jarvis.jarvis_utils import OutputType, PrettyOutput, get_multiline_input, has_uncommitted_changes, user_confirm
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PatchOutputHandler(OutputHandler):
|
|
10
|
+
def name(self) -> str:
|
|
11
|
+
return "PATCH"
|
|
12
|
+
|
|
13
|
+
def handle(self, response: str) -> Tuple[bool, Any]:
|
|
14
|
+
return False, apply_patch(response)
|
|
15
|
+
|
|
16
|
+
def can_handle(self, response: str) -> bool:
|
|
17
|
+
if _parse_patch(response):
|
|
18
|
+
return True
|
|
19
|
+
return False
|
|
20
|
+
|
|
21
|
+
def prompt(self) -> str:
|
|
22
|
+
return """
|
|
23
|
+
# 📝 Patch Format
|
|
24
|
+
Use patch blocks to specify code changes:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
<PATCH>
|
|
28
|
+
path/to/file start,end
|
|
29
|
+
new_content
|
|
30
|
+
</PATCH>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
# 📋 Format Rules
|
|
34
|
+
1. File Path
|
|
35
|
+
- Use relative path from project root
|
|
36
|
+
- Must be exact and case-sensitive
|
|
37
|
+
- Example: src/module/file.py
|
|
38
|
+
|
|
39
|
+
2. Line Numbers
|
|
40
|
+
- Format: start,end
|
|
41
|
+
- start: First line to modify (included)
|
|
42
|
+
- end: Line after last modified line
|
|
43
|
+
- Both numbers are based on original file
|
|
44
|
+
|
|
45
|
+
3. Special Cases
|
|
46
|
+
- Insert: Use same number for start,end
|
|
47
|
+
- New File: Use 0,0
|
|
48
|
+
- Example: "5,5" inserts before line 5
|
|
49
|
+
|
|
50
|
+
# 📌 Examples
|
|
51
|
+
## Modify Existing Code
|
|
52
|
+
```
|
|
53
|
+
<PATCH>
|
|
54
|
+
src/utils.py 10,15
|
|
55
|
+
def new_function():
|
|
56
|
+
return "modified"
|
|
57
|
+
</PATCH>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Insert New Code
|
|
61
|
+
```
|
|
62
|
+
<PATCH>
|
|
63
|
+
src/main.py 20,20
|
|
64
|
+
new_line_here()
|
|
65
|
+
</PATCH>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Create New File
|
|
69
|
+
```
|
|
70
|
+
<PATCH>
|
|
71
|
+
src/new_file.py 0,0
|
|
72
|
+
def new_function():
|
|
73
|
+
pass
|
|
74
|
+
</PATCH>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
# ❗ Important Rules
|
|
78
|
+
1. ONE modification per patch block
|
|
79
|
+
2. Include necessary context
|
|
80
|
+
3. Match existing code style
|
|
81
|
+
4. Preserve indentation
|
|
82
|
+
5. Use exact file paths
|
|
83
|
+
"""
|
|
6
84
|
|
|
7
85
|
|
|
8
86
|
def _parse_patch(patch_str: str) -> Dict[str, List[Dict[str, Any]]]:
|
|
@@ -5,55 +5,95 @@ from typing import Dict, List, Optional, Tuple
|
|
|
5
5
|
from jarvis.jarvis_code_agent.file_select import select_files
|
|
6
6
|
from jarvis.jarvis_codebase.main import CodeBase
|
|
7
7
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
8
|
-
from jarvis.
|
|
8
|
+
from jarvis.jarvis_utils import OutputType, PrettyOutput
|
|
9
9
|
|
|
10
10
|
def make_question(requirement: str) -> Optional[str]:
|
|
11
11
|
"""Generate structured questions to gather necessary information for the requirement."""
|
|
12
|
-
prompt = f"""
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- Extension mechanisms and patterns
|
|
16
|
-
- Related components and their interactions
|
|
17
|
-
|
|
18
|
-
Key Instructions:
|
|
19
|
-
1. Focus on understanding the EXISTING system
|
|
20
|
-
2. Ask about interfaces, hooks, and extension points
|
|
21
|
-
3. Investigate integration patterns and dependencies
|
|
22
|
-
4. Explore current implementation details
|
|
23
|
-
|
|
24
|
-
For example:
|
|
25
|
-
BAD: "How should we implement the new feature?"
|
|
26
|
-
GOOD: "What are the existing extension points in the authentication system that we can use to add the new OAuth provider? Specifically, how does AuthProvider interface work and where is it currently used?"
|
|
27
|
-
|
|
28
|
-
Consider these investigation aspects:
|
|
29
|
-
|
|
30
|
-
1. System Architecture:
|
|
31
|
-
- "What are the existing interfaces/classes that handle [functionality]?"
|
|
32
|
-
- "How is [feature] currently integrated with other components?"
|
|
33
|
-
- "Where are the extension points for [system component]?"
|
|
34
|
-
|
|
35
|
-
2. Implementation Details:
|
|
36
|
-
- "What is the current workflow for [operation] in the system?"
|
|
37
|
-
- "How does the system expose hooks/callbacks for [functionality]?"
|
|
38
|
-
- "Which interfaces/abstract classes are used for [feature] extensibility?"
|
|
39
|
-
|
|
40
|
-
3. Integration Patterns:
|
|
41
|
-
- "How do existing components integrate with [system part]?"
|
|
42
|
-
- "What are the current integration points for [feature]?"
|
|
43
|
-
- "How does the system handle extensions to [component]?"
|
|
44
|
-
|
|
45
|
-
4. Extension Mechanisms:
|
|
46
|
-
- "What patterns are used for extending [functionality]?"
|
|
47
|
-
- "How do existing plugins/extensions connect to [system]?"
|
|
48
|
-
- "Where are the configuration points for [feature] customization?"
|
|
12
|
+
prompt = f"""
|
|
13
|
+
# 🔍 Role Definition
|
|
14
|
+
You are a code analysis expert who helps developers understand existing system implementations by asking targeted questions.
|
|
49
15
|
|
|
50
|
-
|
|
51
|
-
|
|
16
|
+
# 🎯 Core Objectives
|
|
17
|
+
- Understand current system implementations
|
|
18
|
+
- Identify integration points and interfaces
|
|
19
|
+
- Discover extension mechanisms
|
|
20
|
+
- Map component interactions
|
|
21
|
+
|
|
22
|
+
# 📋 Question Categories
|
|
23
|
+
## 1. System Architecture
|
|
24
|
+
Focus on system structure and design:
|
|
25
|
+
- Existing interfaces and classes
|
|
26
|
+
- Component integration patterns
|
|
27
|
+
- Extension points and hooks
|
|
28
|
+
- System boundaries
|
|
29
|
+
|
|
30
|
+
## 2. Implementation Details
|
|
31
|
+
Explore current codebase:
|
|
32
|
+
- Workflow implementations
|
|
33
|
+
- Hook and callback systems
|
|
34
|
+
- Interface hierarchies
|
|
35
|
+
- Extension mechanisms
|
|
36
|
+
|
|
37
|
+
## 3. Integration Patterns
|
|
38
|
+
Understand connection points:
|
|
39
|
+
- Component interactions
|
|
40
|
+
- Integration interfaces
|
|
41
|
+
- Extension methods
|
|
42
|
+
- Plugin systems
|
|
43
|
+
|
|
44
|
+
## 4. Extension Mechanisms
|
|
45
|
+
Identify customization options:
|
|
46
|
+
- Extension patterns
|
|
47
|
+
- Plugin architectures
|
|
48
|
+
- Configuration systems
|
|
49
|
+
- Customization points
|
|
50
|
+
|
|
51
|
+
# 📝 Question Guidelines
|
|
52
|
+
## Good Questions
|
|
53
|
+
- "What interfaces currently handle user authentication?"
|
|
54
|
+
- "How does the system expose extension points for plugins?"
|
|
55
|
+
- "Where are the existing hooks for custom providers?"
|
|
56
|
+
|
|
57
|
+
## Bad Questions
|
|
58
|
+
- "How should we implement the new feature?"
|
|
59
|
+
- "What's the best way to add this?"
|
|
60
|
+
- "Should we create a new class?"
|
|
52
61
|
|
|
53
|
-
|
|
62
|
+
# 🎨 Question Template
|
|
63
|
+
```
|
|
54
64
|
<QUESTION>
|
|
55
|
-
[
|
|
65
|
+
[3-5 specific questions about existing implementations:
|
|
66
|
+
1. System architecture question
|
|
67
|
+
2. Implementation details question
|
|
68
|
+
3. Integration or extension question]
|
|
56
69
|
</QUESTION>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
# 🔎 Investigation Focus
|
|
73
|
+
1. Current System
|
|
74
|
+
- Existing implementations
|
|
75
|
+
- Active interfaces
|
|
76
|
+
- Current patterns
|
|
77
|
+
|
|
78
|
+
2. Integration Points
|
|
79
|
+
- Connection methods
|
|
80
|
+
- Extension hooks
|
|
81
|
+
- Plugin systems
|
|
82
|
+
|
|
83
|
+
3. Extension Options
|
|
84
|
+
- Customization points
|
|
85
|
+
- Configuration options
|
|
86
|
+
- Extension patterns
|
|
87
|
+
|
|
88
|
+
# ❗ Important Rules
|
|
89
|
+
1. Focus on EXISTING code
|
|
90
|
+
2. Ask about current patterns
|
|
91
|
+
3. Explore extension points
|
|
92
|
+
4. Investigate interfaces
|
|
93
|
+
5. Map dependencies
|
|
94
|
+
|
|
95
|
+
User Requirement:
|
|
96
|
+
{requirement}
|
|
57
97
|
"""
|
|
58
98
|
model = PlatformRegistry().get_thinking_platform()
|
|
59
99
|
response = model.chat_until_success(prompt)
|
jarvis/jarvis_codebase/main.py
CHANGED
|
@@ -7,8 +7,8 @@ from typing import List, Tuple, Optional, Dict
|
|
|
7
7
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
8
8
|
import concurrent.futures
|
|
9
9
|
from concurrent.futures import ThreadPoolExecutor
|
|
10
|
-
from jarvis.
|
|
11
|
-
from jarvis.
|
|
10
|
+
from jarvis.jarvis_utils import OutputType, PrettyOutput, find_git_root, get_context_token_count, get_embedding, get_file_md5, get_max_token_count, get_thread_count, load_embedding_model, user_confirm
|
|
11
|
+
from jarvis.jarvis_utils import init_env
|
|
12
12
|
import argparse
|
|
13
13
|
import pickle
|
|
14
14
|
import lzma # 添加 lzma 导入
|
|
@@ -787,23 +787,48 @@ Please provide 10 search-optimized expressions in the specified format.
|
|
|
787
787
|
|
|
788
788
|
if not files_from_codebase:
|
|
789
789
|
PrettyOutput.print("没有找到相关文件", output_type=OutputType.WARNING)
|
|
790
|
-
return [],""
|
|
790
|
+
return [], ""
|
|
791
791
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
792
|
+
prompt = f"""
|
|
793
|
+
# 🤖 Role Definition
|
|
794
|
+
You are a code analysis expert who provides comprehensive and accurate answers about codebases.
|
|
795
|
+
|
|
796
|
+
# 🎯 Core Responsibilities
|
|
797
|
+
- Analyze code files thoroughly
|
|
798
|
+
- Explain technical concepts clearly
|
|
799
|
+
- Provide relevant code examples
|
|
800
|
+
- Identify missing information
|
|
801
|
+
- Answer in user's language
|
|
802
|
+
|
|
803
|
+
# 📋 Response Requirements
|
|
804
|
+
## Content Quality
|
|
805
|
+
- Focus on implementation details
|
|
806
|
+
- Be technically precise
|
|
807
|
+
- Include relevant code snippets
|
|
808
|
+
- Indicate any missing information
|
|
809
|
+
- Use professional terminology
|
|
810
|
+
|
|
811
|
+
## Response Format
|
|
812
|
+
```yaml
|
|
813
|
+
- question: [Restate the question]
|
|
814
|
+
answer: |
|
|
815
|
+
[Detailed technical answer with:
|
|
816
|
+
- Implementation details
|
|
817
|
+
- Code examples (if relevant)
|
|
818
|
+
- Missing information (if any)
|
|
819
|
+
- Related technical concepts]
|
|
820
|
+
|
|
821
|
+
- question: [Follow-up question if needed]
|
|
822
|
+
answer: |
|
|
823
|
+
[Additional technical details]
|
|
824
|
+
```
|
|
825
|
+
|
|
826
|
+
# 🔍 Analysis Context
|
|
803
827
|
Question: {query}
|
|
804
828
|
|
|
805
|
-
Relevant
|
|
829
|
+
Relevant Code Files (by relevance):
|
|
806
830
|
"""
|
|
831
|
+
|
|
807
832
|
# Add context with length control
|
|
808
833
|
available_count = self.max_token_count - get_context_token_count(prompt) - 1000 # Reserve space for answer
|
|
809
834
|
current_count = 0
|
|
@@ -812,10 +837,11 @@ Relevant code files (ordered by relevance):
|
|
|
812
837
|
try:
|
|
813
838
|
content = open(path["file"], "r", encoding="utf-8").read()
|
|
814
839
|
file_content = f"""
|
|
815
|
-
File: {path["file"]}
|
|
816
|
-
|
|
840
|
+
## File: {path["file"]}
|
|
841
|
+
```
|
|
817
842
|
{content}
|
|
818
|
-
|
|
843
|
+
```
|
|
844
|
+
---
|
|
819
845
|
"""
|
|
820
846
|
if current_count + get_context_token_count(file_content) > available_count:
|
|
821
847
|
PrettyOutput.print(
|
|
@@ -831,17 +857,19 @@ Content:
|
|
|
831
857
|
PrettyOutput.print(f"读取 {path} 失败: {str(e)}",
|
|
832
858
|
output_type=OutputType.ERROR)
|
|
833
859
|
continue
|
|
834
|
-
|
|
835
|
-
model = PlatformRegistry.get_global_platform_registry().get_thinking_platform()
|
|
836
860
|
|
|
837
861
|
prompt += """
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
862
|
+
# ❗ Important Rules
|
|
863
|
+
1. Always base answers on provided code
|
|
864
|
+
2. Use technical precision
|
|
865
|
+
3. Include code examples when relevant
|
|
866
|
+
4. Indicate any missing information
|
|
867
|
+
5. Maintain professional language
|
|
868
|
+
6. Answer in user's language
|
|
843
869
|
"""
|
|
844
870
|
|
|
871
|
+
model = PlatformRegistry.get_global_platform_registry().get_thinking_platform()
|
|
872
|
+
|
|
845
873
|
return files_from_codebase, model.chat_until_success(prompt)
|
|
846
874
|
|
|
847
875
|
def is_index_generated(self) -> bool:
|