jarvis-ai-assistant 0.1.125__py3-none-any.whl → 0.1.126__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 (44) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +116 -116
  3. jarvis/jarvis_code_agent/code_agent.py +96 -100
  4. jarvis/jarvis_code_agent/patch.py +39 -47
  5. jarvis/jarvis_code_agent/shell_input_handler.py +22 -0
  6. jarvis/jarvis_codebase/main.py +83 -84
  7. jarvis/jarvis_dev/main.py +691 -713
  8. jarvis/jarvis_lsp/base.py +0 -12
  9. jarvis/jarvis_lsp/cpp.py +0 -9
  10. jarvis/jarvis_lsp/go.py +0 -9
  11. jarvis/jarvis_lsp/python.py +0 -28
  12. jarvis/jarvis_lsp/registry.py +0 -1
  13. jarvis/jarvis_lsp/rust.py +0 -9
  14. jarvis/jarvis_multi_agent/__init__.py +52 -52
  15. jarvis/jarvis_tools/ask_codebase.py +6 -6
  16. jarvis/jarvis_tools/ask_user.py +2 -2
  17. jarvis/jarvis_tools/base.py +4 -4
  18. jarvis/jarvis_tools/chdir.py +8 -8
  19. jarvis/jarvis_tools/code_review.py +6 -6
  20. jarvis/jarvis_tools/create_code_agent.py +4 -4
  21. jarvis/jarvis_tools/create_sub_agent.py +7 -7
  22. jarvis/jarvis_tools/execute_shell.py +54 -21
  23. jarvis/jarvis_tools/execute_shell_script.py +3 -3
  24. jarvis/jarvis_tools/file_operation.py +36 -8
  25. jarvis/jarvis_tools/git_commiter.py +16 -16
  26. jarvis/jarvis_tools/lsp_find_definition.py +7 -7
  27. jarvis/jarvis_tools/lsp_prepare_rename.py +7 -7
  28. jarvis/jarvis_tools/methodology.py +6 -6
  29. jarvis/jarvis_tools/rag.py +5 -5
  30. jarvis/jarvis_tools/read_webpage.py +2 -2
  31. jarvis/jarvis_tools/registry.py +139 -139
  32. jarvis/jarvis_tools/search_web.py +5 -5
  33. jarvis/jarvis_tools/select_code_files.py +3 -3
  34. jarvis/jarvis_tools/tool_generator.py +33 -34
  35. jarvis/jarvis_utils/methodology.py +5 -5
  36. {jarvis_ai_assistant-0.1.125.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/METADATA +31 -17
  37. jarvis_ai_assistant-0.1.126.dist-info/RECORD +74 -0
  38. {jarvis_ai_assistant-0.1.125.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/WHEEL +1 -1
  39. jarvis/jarvis_tools/lsp_validate_edit.py +0 -141
  40. jarvis/jarvis_tools/read_code.py +0 -192
  41. jarvis_ai_assistant-0.1.125.dist-info/RECORD +0 -75
  42. {jarvis_ai_assistant-0.1.125.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/LICENSE +0 -0
  43. {jarvis_ai_assistant-0.1.125.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/entry_points.txt +0 -0
  44. {jarvis_ai_assistant-0.1.125.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/top_level.txt +0 -0
@@ -5,8 +5,8 @@ import os
5
5
  from jarvis.jarvis_agent.output_handler import OutputHandler
6
6
  from jarvis.jarvis_platform.registry import PlatformRegistry
7
7
  from jarvis.jarvis_tools.git_commiter import GitCommitTool
8
- from jarvis.jarvis_tools.file_operation import FileOperationTool
9
8
  from jarvis.jarvis_tools.execute_shell_script import ShellScriptTool
9
+ from jarvis.jarvis_tools.file_operation import FileOperationTool
10
10
  from jarvis.jarvis_utils.config import is_confirm_before_apply_patch
11
11
  from jarvis.jarvis_utils.git_utils import get_commits_between, get_latest_commit_hash
12
12
  from jarvis.jarvis_utils.input import get_multiline_input
@@ -26,31 +26,31 @@ class PatchOutputHandler(OutputHandler):
26
26
 
27
27
  def prompt(self) -> str:
28
28
  return """
29
- # 🛠️ Contextual Code Patch Specification
30
- Use <PATCH> blocks to specify code changes:
29
+ # 🛠️ 上下文代码补丁规范
30
+ 使用<PATCH>块来指定代码更改:
31
31
  --------------------------------
32
32
  <PATCH>
33
- File: [file_path]
34
- Reason: [change_reason]
35
- [contextual_code_snippet]
33
+ File: [文件路径]
34
+ Reason: [修改原因]
35
+ [上下文代码片段]
36
36
  </PATCH>
37
37
  --------------------------------
38
- Rules:
39
- 1. Code snippets must include sufficient context (3 lines before/after)
40
- 2. I can see full code, so only show modified code sections
41
- 3. Preserve original indentation and formatting
42
- 4. For new files, provide complete code
43
- 5. When modifying existing files, retain surrounding unchanged code
44
- Example:
38
+ 规则:
39
+ 1. 代码片段必须包含足够的上下文(前后各3行)
40
+ 2. 我可以看到完整代码,所以只需显示修改的代码部分
41
+ 3. 保留原始缩进和格式
42
+ 4. 对于新文件,提供完整代码
43
+ 5. 修改现有文件时,保留周围未更改的代码
44
+ 示例:
45
45
  <PATCH>
46
46
  File: src/utils/math.py
47
- Reason: Fix zero division handling
47
+ Reason: 修复除零处理
48
48
  def safe_divide(a, b):
49
- # Add parameter validation
49
+ # 添加参数验证
50
50
  if b == 0:
51
- raise ValueError("Divisor cannot be zero")
51
+ raise ValueError("除数不能为零")
52
52
  return a / b
53
- # existing code ...
53
+ # 现有代码 ...
54
54
  def add(a, b):
55
55
  return a + b
56
56
  </PATCH>
@@ -102,16 +102,21 @@ def apply_patch(output_str: str) -> str:
102
102
 
103
103
  # 添加提交信息到final_ret
104
104
  if commits:
105
- final_ret += "✅ The patches have been applied\n"
106
- final_ret += "Commit History:\n"
105
+ final_ret += "✅ 补丁已应用\n"
106
+ final_ret += "提交信息:\n"
107
107
  for commit_hash, commit_message in commits:
108
108
  final_ret += f"- {commit_hash[:7]}: {commit_message}\n"
109
+
110
+ final_ret += f"应用补丁后的代码:\n{diff}"
111
+
109
112
  else:
110
- final_ret += "✅ The patches have been applied (no new commits)"
113
+ final_ret += "✅ 补丁已应用(没有新的提交)"
111
114
  else:
112
- final_ret += "❌ I don't want to commit the code"
115
+ final_ret += "❌ 我不想提交代码\n"
116
+ final_ret += "之前的代码:\n"
117
+ final_ret += diff
113
118
  else:
114
- final_ret += "❌ There are no changes to commit"
119
+ final_ret += "❌ 没有要提交的更改\n"
115
120
  # 用户确认最终结果
116
121
  PrettyOutput.print(final_ret, OutputType.USER)
117
122
  if not is_confirm_before_apply_patch() or user_confirm("是否使用此回复?", default=True):
@@ -182,22 +187,22 @@ def handle_code_operation(filepath: str, patch_content: str) -> str:
182
187
  return f"文件读取失败: {old_file_content['stderr']}"
183
188
 
184
189
  prompt = f"""
185
- You are a code reviewer, please review the following code and merge the code with the context.
186
- Original Code:
190
+ 你是一个代码审查员,请审查以下代码并将其与上下文合并。
191
+ 原始代码:
187
192
  {old_file_content["stdout"]}
188
- Patch:
193
+ 补丁内容:
189
194
  {patch_content}
190
195
  """
191
196
  prompt += f"""
192
- Please merge the code with the context and return the fully merged code.
197
+ 请将代码与上下文合并并返回完整的合并代码。
193
198
 
194
- Requirements:
195
- 1. Strictly preserve original code formatting and indentation
196
- 2. Only include actual code content in <MERGED_CODE> block
197
- 3. Absolutely NO markdown code blocks (```) or backticks
198
- 4. Maintain exact line numbers from original code except for changes
199
+ 要求:
200
+ 1. 严格保留原始代码的格式、空行和缩进
201
+ 2. 仅在<MERGED_CODE>块中包含实际代码内容,包括空行和缩进
202
+ 3. 绝对不要使用markdown代码块(```)或反引号,除非修改的是markdown文件
203
+ 4. 除了合并后的代码,不要输出任何其他文本
199
204
 
200
- Output Format:
205
+ 输出格式:
201
206
  <MERGED_CODE>
202
207
  [merged_code]
203
208
  </MERGED_CODE>
@@ -225,7 +230,7 @@ Output Format:
225
230
  if end_line == -1:
226
231
  last_line = response[-1]
227
232
  prompt = f"""
228
- continue with the last line:
233
+ 继续从最后一行开始(不要包含<MERGED_CODE>标签,完成后输出</MERGED_CODE>标签):
229
234
  {last_line}
230
235
  """
231
236
  response.pop() # 删除最后一行
@@ -236,21 +241,8 @@ Output Format:
236
241
  break
237
242
  # 写入合并后的代码
238
243
  with open(filepath, 'w', encoding='utf-8') as f:
239
- f.write("\n".join(response[start_line:end_line]))
244
+ f.write("\n".join(response[start_line:end_line])+"\n")
240
245
  PrettyOutput.print(f"✅ 为文件 {filepath} 应用补丁成功", OutputType.SUCCESS)
241
246
  return ""
242
247
  except Exception as e:
243
248
  return f"文件操作失败: {str(e)}"
244
- def shell_input_handler(user_input: str, agent: Any) -> Tuple[str, bool]:
245
- lines = user_input.splitlines()
246
- cmdline = [line for line in lines if line.startswith("!")]
247
- if len(cmdline) == 0:
248
- return user_input, False
249
- else:
250
- script = '\n'.join([c[1:] for c in cmdline])
251
- PrettyOutput.print(script, OutputType.CODE, lang="bash")
252
- if user_confirm(f"是否要执行以上shell脚本?", default=True):
253
- ShellScriptTool().execute({"script_content": script})
254
- return "", True
255
- return user_input, False
256
-
@@ -0,0 +1,22 @@
1
+
2
+
3
+ from typing import Any, Tuple
4
+
5
+ from jarvis.jarvis_tools.execute_shell_script import ShellScriptTool
6
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
7
+ from jarvis.jarvis_utils.utils import user_confirm
8
+
9
+
10
+ def shell_input_handler(user_input: str, agent: Any) -> Tuple[str, bool]:
11
+ lines = user_input.splitlines()
12
+ cmdline = [line for line in lines if line.startswith("!")]
13
+ if len(cmdline) == 0:
14
+ return user_input, False
15
+ else:
16
+ script = '\n'.join([c[1:] for c in cmdline])
17
+ PrettyOutput.print(script, OutputType.CODE, lang="bash")
18
+ if user_confirm(f"是否要执行以上shell脚本?", default=True):
19
+ ShellScriptTool().execute({"script_content": script})
20
+ return "", True
21
+ return user_input, False
22
+
@@ -76,13 +76,13 @@ class CodeBase:
76
76
  model.set_suppress_output(True)
77
77
  else:
78
78
  PrettyOutput.print(f"为 {file_path} 生成描述 ...", output_type=OutputType.PROGRESS)
79
- prompt = f"""Please analyze the following code file and generate a detailed description. The description should include:
80
- 1. Overall file functionality description
81
- 2. description for each global variable, function, type definition, class, method, and other code elements
79
+ prompt = f"""请分析以下代码文件并生成详细描述。描述应包含:
80
+ 1. 文件整体功能描述
81
+ 2. 对每个全局变量、函数、类型定义、类、方法和其他代码元素的描述
82
82
 
83
- Please use concise and professional language, emphasizing technical functionality to facilitate subsequent code retrieval.
84
- File path: {file_path}
85
- Code content:
83
+ 请使用简洁专业的语言,强调技术功能,以便于后续代码检索。
84
+ 文件路径: {file_path}
85
+ 代码内容:
86
86
  {content}
87
87
  """
88
88
  response = model.chat_until_success(prompt)
@@ -320,7 +320,7 @@ Content: {content}
320
320
  ids = []
321
321
  self.file_paths = [] # Reset the file path list
322
322
 
323
- for i, (file_path, data) in enumerate(self.vector_cache.items()):
323
+ for i, ( file_path, data) in enumerate(self.vector_cache.items()):
324
324
  if "vector" not in data:
325
325
  PrettyOutput.print(f"无效的缓存数据 {file_path}: 缺少向量",
326
326
  output_type=OutputType.WARNING)
@@ -595,24 +595,24 @@ Content: {content}
595
595
 
596
596
  def _process_batch(self, query: str, files_info: List[str]) -> List[Dict[str, str]]:
597
597
  """Process a batch of files"""
598
- prompt = f"""As a code analysis expert, please help identify the most relevant files for the given query using chain-of-thought reasoning.
598
+ prompt = f"""作为一名代码分析专家,请使用链式思维推理帮助识别与给定查询最相关的文件。
599
599
 
600
- Query: {query}
600
+ 查询: {query}
601
601
 
602
- Available files:
602
+ 可用文件:
603
603
  {''.join(files_info)}
604
604
 
605
- Think through this step by step:
606
- 1. First, analyze the query to identify key requirements and technical concepts
607
- 2. For each file:
608
- - Examine its path and content
609
- - Assess how it relates to the query's requirements
610
- - Consider both direct and indirect relationships
611
- - Rate its relevance (high/medium/low)
612
- 3. Select only files with clear relevance to the query
613
- 4. Order files by relevance, with most relevant first
614
-
615
- Please output your selection in YAML format:
605
+ 请按以下步骤思考:
606
+ 1. 首先,分析查询以识别关键需求和技术概念
607
+ 2. 对于每个文件:
608
+ - 检查其路径和内容
609
+ - 评估其与查询需求的关系
610
+ - 考虑直接和间接关系
611
+ - 评估其相关性(高/中/低)
612
+ 3. 仅选择与查询明确相关的文件
613
+ 4. 按相关性排序,最相关的文件在前
614
+
615
+ 请以YAML格式输出您的选择:
616
616
  <FILES>
617
617
  - file: path/to/most/relevant.py
618
618
  reason: xxxxxxxxxx
@@ -620,12 +620,12 @@ Please output your selection in YAML format:
620
620
  reason: yyyyyyyyyy
621
621
  </FILES>
622
622
 
623
- Important:
624
- - Only include files that are truly relevant
625
- - Exclude files with weak or unclear connections
626
- - Focus on implementation rather than test files
627
- - Consider both file paths and content
628
- - Only output the file paths, no other text
623
+ 重要提示:
624
+ - 仅包含真正相关的文件
625
+ - 排除连接不明确或较弱的文件
626
+ - 重点关注实现文件而非测试文件
627
+ - 同时考虑文件路径和内容
628
+ - 仅输出文件路径,不要包含其他文本
629
629
  """
630
630
 
631
631
  # Use a large model to evaluate
@@ -657,29 +657,28 @@ Important:
657
657
  """
658
658
  model = PlatformRegistry.get_global_platform_registry().get_normal_platform()
659
659
  model.set_suppress_output(True)
660
- prompt = f"""Please generate 10 different expressions optimized for vector search based on the following query. Each expression should:
661
-
662
- 1. Focus on key technical concepts and terminology
663
- 2. Use clear and specific language
664
- 3. Include important contextual terms
665
- 4. Avoid general or ambiguous words
666
- 5. Maintain semantic similarity with original query
667
- 6. Be suitable for embedding-based search
668
-
669
- Original query:
660
+ prompt = f"""请基于以下查询生成10个针对向量搜索优化的不同表达。每个表达应满足:
661
+ 1. 聚焦关键技术概念和术语
662
+ 2. 使用清晰明确的语言
663
+ 3. 包含重要的上下文术语
664
+ 4. 避免使用通用或模糊的词语
665
+ 5. 保持与原始查询的语义相似性
666
+ 6. 适合基于嵌入的搜索
667
+
668
+ 原始查询:
670
669
  {query}
671
670
 
672
- Example transformations:
673
- Query: "How to handle user login?"
674
- Output format:
671
+ 示例转换:
672
+ 查询: "如何处理用户登录?"
673
+ 输出格式:
675
674
  <QUESTION>
676
- - user authentication implementation and flow
677
- - login system architecture and components
678
- - credential validation and session management
675
+ - 用户认证的实现与流程
676
+ - 登录系统架构与组件
677
+ - 凭证验证与会话管理
679
678
  - ...
680
679
  </QUESTION>
681
680
 
682
- Please provide 10 search-optimized expressions in the specified format.
681
+ 请以指定格式提供10个搜索优化的表达。
683
682
  """
684
683
  response = model.chat_until_success(prompt)
685
684
 
@@ -794,52 +793,52 @@ Please provide 10 search-optimized expressions in the specified format.
794
793
  return [], ""
795
794
 
796
795
  prompt = f"""
797
- # 🤖 Role Definition
798
- You are a code analysis expert who provides comprehensive and accurate answers about codebases.
799
-
800
- # 🎯 Core Responsibilities
801
- - Analyze code files thoroughly
802
- - Explain technical concepts clearly
803
- - Provide relevant code examples
804
- - Identify missing information
805
- - Answer in user's language
806
-
807
- # 📋 Response Requirements
808
- ## Content Quality
809
- - Focus on implementation details
810
- - Be technically precise
811
- - Include relevant code snippets
812
- - Indicate any missing information
813
- - Use professional terminology
814
-
815
- ## Response Format
816
- - question: [Restate the question]
796
+ # 🤖 角色定义
797
+ 您是一位代码分析专家,能够提供关于代码库的全面且准确的回答。
798
+
799
+ # 🎯 核心职责
800
+ - 深入分析代码文件
801
+ - 清晰解释技术概念
802
+ - 提供相关代码示例
803
+ - 识别缺失的信息
804
+ - 使用用户的语言进行回答
805
+
806
+ # 📋 回答要求
807
+ ## 内容质量
808
+ - 关注实现细节
809
+ - 保持技术准确性
810
+ - 包含相关代码片段
811
+ - 指出任何缺失的信息
812
+ - 使用专业术语
813
+
814
+ ## 回答格式
815
+ - question: [重述问题]
817
816
  answer: |
818
- [Detailed technical answer with:
819
- - Implementation details
820
- - Code examples (if relevant)
821
- - Missing information (if any)
822
- - Related technical concepts]
817
+ [详细的技术回答,包含:
818
+ - 实现细节
819
+ - 代码示例(如果相关)
820
+ - 缺失的信息(如果有)
821
+ - 相关技术概念]
823
822
 
824
- - question: [Follow-up question if needed]
823
+ - question: [如果需要,提出后续问题]
825
824
  answer: |
826
- [Additional technical details]
825
+ [额外的技术细节]
827
826
 
828
- # 🔍 Analysis Context
829
- Question: {query}
827
+ # 🔍 分析上下文
828
+ 问题: {query}
830
829
 
831
- Relevant Code Files (by relevance):
830
+ 相关代码文件(按相关性排序):
832
831
  """
833
832
 
834
- # Add context with length control
835
- available_count = self.max_token_count - get_context_token_count(prompt) - 1000 # Reserve space for answer
833
+ # 添加上下文,控制长度
834
+ available_count = self.max_token_count - get_context_token_count(prompt) - 1000 # 为回答预留空间
836
835
  current_count = 0
837
836
 
838
837
  for path in files_from_codebase:
839
838
  try:
840
839
  content = open(path["file"], "r", encoding="utf-8").read()
841
840
  file_content = f"""
842
- ## File: {path["file"]}
841
+ ## 文件: {path["file"]}
843
842
  ```
844
843
  {content}
845
844
  ```
@@ -861,13 +860,13 @@ Relevant Code Files (by relevance):
861
860
  continue
862
861
 
863
862
  prompt += """
864
- # ❗ Important Rules
865
- 1. Always base answers on provided code
866
- 2. Use technical precision
867
- 3. Include code examples when relevant
868
- 4. Indicate any missing information
869
- 5. Maintain professional language
870
- 6. Answer in user's language
863
+ # ❗ 重要规则
864
+ 1. 始终基于提供的代码进行回答
865
+ 2. 保持技术准确性
866
+ 3. 在相关时包含代码示例
867
+ 4. 指出任何缺失的信息
868
+ 5. 保持专业语言
869
+ 6. 使用用户的语言进行回答
871
870
  """
872
871
 
873
872
  model = PlatformRegistry.get_global_platform_registry().get_thinking_platform()