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.

Files changed (51) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/{agent.py → jarvis_agent/__init__.py} +122 -203
  3. jarvis/jarvis_agent/output_handler.py +23 -0
  4. jarvis/jarvis_code_agent/code_agent.py +113 -100
  5. jarvis/jarvis_code_agent/file_select.py +28 -7
  6. jarvis/jarvis_code_agent/patch.py +80 -2
  7. jarvis/jarvis_code_agent/relevant_files.py +82 -42
  8. jarvis/jarvis_codebase/main.py +53 -25
  9. jarvis/jarvis_dev/main.py +719 -547
  10. jarvis/jarvis_lsp/cpp.py +1 -1
  11. jarvis/jarvis_lsp/go.py +1 -1
  12. jarvis/jarvis_lsp/registry.py +1 -1
  13. jarvis/jarvis_lsp/rust.py +1 -1
  14. jarvis/jarvis_multi_agent/__init__.py +170 -0
  15. jarvis/jarvis_platform/ai8.py +2 -2
  16. jarvis/jarvis_platform/base.py +14 -4
  17. jarvis/jarvis_platform/kimi.py +2 -2
  18. jarvis/jarvis_platform/ollama.py +1 -1
  19. jarvis/jarvis_platform/openai.py +1 -1
  20. jarvis/jarvis_platform/oyi.py +1 -1
  21. jarvis/jarvis_platform/registry.py +1 -1
  22. jarvis/jarvis_platform_manager/main.py +422 -6
  23. jarvis/jarvis_platform_manager/openai_test.py +139 -0
  24. jarvis/jarvis_rag/main.py +57 -20
  25. jarvis/jarvis_smart_shell/main.py +55 -29
  26. jarvis/jarvis_tools/ask_codebase.py +1 -1
  27. jarvis/jarvis_tools/ask_user.py +1 -1
  28. jarvis/jarvis_tools/chdir.py +1 -1
  29. jarvis/jarvis_tools/code_review.py +3 -3
  30. jarvis/jarvis_tools/create_code_agent.py +1 -1
  31. jarvis/jarvis_tools/create_sub_agent.py +2 -2
  32. jarvis/jarvis_tools/execute_shell.py +1 -1
  33. jarvis/jarvis_tools/file_operation.py +16 -14
  34. jarvis/jarvis_tools/git_commiter.py +2 -2
  35. jarvis/jarvis_tools/methodology.py +1 -1
  36. jarvis/jarvis_tools/rag.py +1 -1
  37. jarvis/jarvis_tools/read_code.py +19 -8
  38. jarvis/jarvis_tools/read_webpage.py +1 -1
  39. jarvis/jarvis_tools/registry.py +157 -31
  40. jarvis/jarvis_tools/search.py +1 -1
  41. jarvis/jarvis_tools/select_code_files.py +1 -1
  42. jarvis/{utils.py → jarvis_utils/__init__.py} +69 -53
  43. {jarvis_ai_assistant-0.1.115.dist-info → jarvis_ai_assistant-0.1.117.dist-info}/METADATA +1 -1
  44. jarvis_ai_assistant-0.1.117.dist-info/RECORD +65 -0
  45. {jarvis_ai_assistant-0.1.115.dist-info → jarvis_ai_assistant-0.1.117.dist-info}/WHEEL +1 -1
  46. {jarvis_ai_assistant-0.1.115.dist-info → jarvis_ai_assistant-0.1.117.dist-info}/entry_points.txt +1 -1
  47. jarvis/multi_agent.py +0 -76
  48. jarvis/utils/date_utils.py +0 -19
  49. jarvis_ai_assistant-0.1.115.dist-info/RECORD +0 -64
  50. {jarvis_ai_assistant-0.1.115.dist-info → jarvis_ai_assistant-0.1.117.dist-info}/LICENSE +0 -0
  51. {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.agent import Agent
5
- from jarvis.jarvis_code_agent.patch import apply_patch
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.utils import OutputType, PrettyOutput, get_multiline_input, has_uncommitted_changes, init_env, find_git_root
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 = """You are a code agent responsible for modifying code. Your primary task is to understand existing code first and ensure compatibility with the current system.
30
-
31
- # Critical First Steps
32
- 1. READ and UNDERSTAND existing code thoroughly
33
- 2. Identify current patterns and conventions
34
- 3. Map out affected components and their interactions
35
- 4. Plan changes that maintain system integrity
36
-
37
- # Code Completeness Requirements
38
- 1. Implementation Must Be Complete
39
- • NO TODOs or placeholder comments
40
- NO unfinished functions
41
- NO stub implementations
42
- All error cases must be handled
43
- All edge cases must be covered
44
-
45
- 2. Documentation Must Be Complete
46
- • All functions must have docstrings
47
- All parameters must be documented
48
- Return values must be specified
49
- Exceptions must be documented
50
- Complex logic must be explained
51
-
52
- # Patch Format
53
- <PATCH>
54
- path/file start,end
55
- new_content
56
- </PATCH>
57
-
58
- Key Rules:
59
- One modification per patch block
60
- Line numbers are based on original file
61
- Start line is included, end line is excluded
62
- Same start/end number: insert before that line
63
- Start=0, end=0: create new file with content
64
-
65
- # Code Compatibility Requirements
66
- 1. System Integration
67
- MUST preserve existing API contracts
68
- MUST maintain current function signatures
69
- MUST keep data structure compatibility
70
- MUST follow error handling patterns
71
-
72
- 2. Style Consistency
73
- • Match existing naming conventions exactly
74
- Follow established code organization
75
- Use current import style and order
76
- Maintain comment style and level of detail
77
-
78
- 3. Pattern Alignment
79
- • Reuse existing error handling approaches
80
- Follow established design patterns
81
- Use current logging conventions
82
- Keep configuration consistency
83
-
84
- # Development Process
85
- 1. ANALYZE (Current Code)
86
- Read and understand existing implementations
87
- Map out current code structure
88
- Identify established patterns
89
- Note key dependencies
90
-
91
- 2. ASSESS (Changes)
92
- • Evaluate impact on existing code
93
- Check all dependencies
94
- Verify API compatibility
95
- Consider side effects
96
-
97
- 3. IMPLEMENT (Carefully)
98
- Make minimal necessary changes
99
- Follow existing patterns exactly
100
- • Preserve all interfaces
101
- Maintain backward compatibility
102
- Implement completely - no TODOs
103
-
104
- # File Handling
105
- Large Files (>200 lines):
106
- 1. Use grep/find to locate relevant sections
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
- # Available Tools
111
- Primary:
112
- read_code - MUST use to understand existing code
113
- LSP tools for code analysis
114
- execute_shell for searches
115
- ask_user when uncertain
116
-
117
- # Quality Requirements
118
- Every Change Must:
119
- ✓ Be based on thorough code reading
120
- Preserve all interfaces
121
- Match existing style exactly
122
- Handle errors consistently
123
- Maintain documentation
124
- Follow project patterns
125
- Be completely implemented
126
- Have no TODOs or stubs"""
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
- tool_registry=tool_registry,
141
+ output_handler=[tool_registry, PatchOutputHandler()],
133
142
  platform=PlatformRegistry().get_codegen_platform(),
134
143
  record_methodology=False,
135
- output_handler_after_tool=[apply_patch],
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.utils import OutputType, PrettyOutput, get_single_line_input, user_confirm
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
- PrettyOutput.print("找到以下匹配的文件:", OutputType.INFO)
182
+ tips = "找到以下匹配的文件:"
179
183
  for i, path in enumerate(matches, 1):
180
- PrettyOutput.print(f"[{i}] {path}", OutputType.INFO)
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
- PrettyOutput.print(f"文件不存在: {path}", OutputType.ERROR)
204
+ tips += f"\n文件不存在: {path}"
199
205
  continue
200
206
 
201
207
  try:
202
208
  selected_files.append({"file": path, "reason": "User Added"})
203
- PrettyOutput.print(f"文件已添加: {path}", OutputType.SUCCESS)
209
+ tips += f"\n文件已添加: {path}"
204
210
  except Exception as e:
205
- PrettyOutput.print(f"读取文件失败: {str(e)}", OutputType.ERROR)
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 selected_files
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.utils import OutputType, PrettyOutput, get_multiline_input, has_uncommitted_changes, user_confirm
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.utils import OutputType, PrettyOutput
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"""You are a code analysis expert who helps developers understand existing system implementations. Generate specific questions to investigate:
13
- - Current system implementations
14
- - Existing interfaces and integration points
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
- User Requirement:
51
- {requirement}
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
- Output Format:
62
+ # 🎨 Question Template
63
+ ```
54
64
  <QUESTION>
55
- [Write 3-5 specific questions focusing on existing implementations and extension points. Each question should help understand how to integrate with or extend the current system]
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)
@@ -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.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.utils import init_env
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
- # Build enhanced prompt
793
- prompt = f"""Based on the following code files, please provide a comprehensive and accurate answer to the user's question.
794
-
795
- Important guidelines:
796
- 1. Focus on code-specific details and implementation
797
- 2. Explain technical concepts clearly
798
- 3. Include relevant code snippets when helpful
799
- 4. If the code doesn't fully answer the question, indicate what's missing
800
- 5. Answer in user's language.
801
- 6. Answer with professional language.
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 code files (ordered by relevance):
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
- Content:
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
- Output Format:
839
- - question: the question to answer
840
- answer: the answer to the question
841
- - question: the question to answer
842
- answer: the answer to the question
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: