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.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +116 -116
- jarvis/jarvis_code_agent/code_agent.py +96 -100
- jarvis/jarvis_code_agent/patch.py +39 -47
- jarvis/jarvis_code_agent/shell_input_handler.py +22 -0
- jarvis/jarvis_codebase/main.py +83 -84
- jarvis/jarvis_dev/main.py +691 -713
- jarvis/jarvis_lsp/base.py +0 -12
- jarvis/jarvis_lsp/cpp.py +0 -9
- jarvis/jarvis_lsp/go.py +0 -9
- jarvis/jarvis_lsp/python.py +0 -28
- jarvis/jarvis_lsp/registry.py +0 -1
- jarvis/jarvis_lsp/rust.py +0 -9
- jarvis/jarvis_multi_agent/__init__.py +52 -52
- jarvis/jarvis_tools/ask_codebase.py +6 -6
- jarvis/jarvis_tools/ask_user.py +2 -2
- jarvis/jarvis_tools/base.py +4 -4
- jarvis/jarvis_tools/chdir.py +8 -8
- jarvis/jarvis_tools/code_review.py +6 -6
- jarvis/jarvis_tools/create_code_agent.py +4 -4
- jarvis/jarvis_tools/create_sub_agent.py +7 -7
- jarvis/jarvis_tools/execute_shell.py +54 -21
- jarvis/jarvis_tools/execute_shell_script.py +3 -3
- jarvis/jarvis_tools/file_operation.py +36 -8
- jarvis/jarvis_tools/git_commiter.py +16 -16
- jarvis/jarvis_tools/lsp_find_definition.py +7 -7
- jarvis/jarvis_tools/lsp_prepare_rename.py +7 -7
- jarvis/jarvis_tools/methodology.py +6 -6
- jarvis/jarvis_tools/rag.py +5 -5
- jarvis/jarvis_tools/read_webpage.py +2 -2
- jarvis/jarvis_tools/registry.py +139 -139
- jarvis/jarvis_tools/search_web.py +5 -5
- jarvis/jarvis_tools/select_code_files.py +3 -3
- jarvis/jarvis_tools/tool_generator.py +33 -34
- jarvis/jarvis_utils/methodology.py +5 -5
- {jarvis_ai_assistant-0.1.125.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/METADATA +31 -17
- jarvis_ai_assistant-0.1.126.dist-info/RECORD +74 -0
- {jarvis_ai_assistant-0.1.125.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/WHEEL +1 -1
- jarvis/jarvis_tools/lsp_validate_edit.py +0 -141
- jarvis/jarvis_tools/read_code.py +0 -192
- jarvis_ai_assistant-0.1.125.dist-info/RECORD +0 -75
- {jarvis_ai_assistant-0.1.125.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.125.dist-info → jarvis_ai_assistant-0.1.126.dist-info}/entry_points.txt +0 -0
- {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
|
-
# 🛠️
|
|
30
|
-
|
|
29
|
+
# 🛠️ 上下文代码补丁规范
|
|
30
|
+
使用<PATCH>块来指定代码更改:
|
|
31
31
|
--------------------------------
|
|
32
32
|
<PATCH>
|
|
33
|
-
File: [
|
|
34
|
-
Reason: [
|
|
35
|
-
[
|
|
33
|
+
File: [文件路径]
|
|
34
|
+
Reason: [修改原因]
|
|
35
|
+
[上下文代码片段]
|
|
36
36
|
</PATCH>
|
|
37
37
|
--------------------------------
|
|
38
|
-
|
|
39
|
-
1.
|
|
40
|
-
2.
|
|
41
|
-
3.
|
|
42
|
-
4.
|
|
43
|
-
5.
|
|
44
|
-
|
|
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:
|
|
47
|
+
Reason: 修复除零处理
|
|
48
48
|
def safe_divide(a, b):
|
|
49
|
-
#
|
|
49
|
+
# 添加参数验证
|
|
50
50
|
if b == 0:
|
|
51
|
-
raise ValueError("
|
|
51
|
+
raise ValueError("除数不能为零")
|
|
52
52
|
return a / b
|
|
53
|
-
#
|
|
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 += "✅
|
|
106
|
-
final_ret += "
|
|
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 += "✅
|
|
113
|
+
final_ret += "✅ 补丁已应用(没有新的提交)"
|
|
111
114
|
else:
|
|
112
|
-
final_ret += "❌
|
|
115
|
+
final_ret += "❌ 我不想提交代码\n"
|
|
116
|
+
final_ret += "之前的代码:\n"
|
|
117
|
+
final_ret += diff
|
|
113
118
|
else:
|
|
114
|
-
final_ret += "❌
|
|
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
|
-
|
|
186
|
-
|
|
190
|
+
你是一个代码审查员,请审查以下代码并将其与上下文合并。
|
|
191
|
+
原始代码:
|
|
187
192
|
{old_file_content["stdout"]}
|
|
188
|
-
|
|
193
|
+
补丁内容:
|
|
189
194
|
{patch_content}
|
|
190
195
|
"""
|
|
191
196
|
prompt += f"""
|
|
192
|
-
|
|
197
|
+
请将代码与上下文合并并返回完整的合并代码。
|
|
193
198
|
|
|
194
|
-
|
|
195
|
-
1.
|
|
196
|
-
2.
|
|
197
|
-
3.
|
|
198
|
-
4.
|
|
199
|
+
要求:
|
|
200
|
+
1. 严格保留原始代码的格式、空行和缩进
|
|
201
|
+
2. 仅在<MERGED_CODE>块中包含实际代码内容,包括空行和缩进
|
|
202
|
+
3. 绝对不要使用markdown代码块(```)或反引号,除非修改的是markdown文件
|
|
203
|
+
4. 除了合并后的代码,不要输出任何其他文本
|
|
199
204
|
|
|
200
|
-
|
|
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
|
-
|
|
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
|
+
|
jarvis/jarvis_codebase/main.py
CHANGED
|
@@ -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"""
|
|
80
|
-
1.
|
|
81
|
-
2.
|
|
79
|
+
prompt = f"""请分析以下代码文件并生成详细描述。描述应包含:
|
|
80
|
+
1. 文件整体功能描述
|
|
81
|
+
2. 对每个全局变量、函数、类型定义、类、方法和其他代码元素的描述
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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"""
|
|
598
|
+
prompt = f"""作为一名代码分析专家,请使用链式思维推理帮助识别与给定查询最相关的文件。
|
|
599
599
|
|
|
600
|
-
|
|
600
|
+
查询: {query}
|
|
601
601
|
|
|
602
|
-
|
|
602
|
+
可用文件:
|
|
603
603
|
{''.join(files_info)}
|
|
604
604
|
|
|
605
|
-
|
|
606
|
-
1.
|
|
607
|
-
2.
|
|
608
|
-
-
|
|
609
|
-
-
|
|
610
|
-
-
|
|
611
|
-
-
|
|
612
|
-
3.
|
|
613
|
-
4.
|
|
614
|
-
|
|
615
|
-
|
|
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
|
-
|
|
624
|
-
-
|
|
625
|
-
-
|
|
626
|
-
-
|
|
627
|
-
-
|
|
628
|
-
-
|
|
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"""
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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
|
-
|
|
673
|
-
|
|
674
|
-
|
|
671
|
+
示例转换:
|
|
672
|
+
查询: "如何处理用户登录?"
|
|
673
|
+
输出格式:
|
|
675
674
|
<QUESTION>
|
|
676
|
-
-
|
|
677
|
-
-
|
|
678
|
-
-
|
|
675
|
+
- 用户认证的实现与流程
|
|
676
|
+
- 登录系统架构与组件
|
|
677
|
+
- 凭证验证与会话管理
|
|
679
678
|
- ...
|
|
680
679
|
</QUESTION>
|
|
681
680
|
|
|
682
|
-
|
|
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
|
-
# 🤖
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
# 🎯
|
|
801
|
-
-
|
|
802
|
-
-
|
|
803
|
-
-
|
|
804
|
-
-
|
|
805
|
-
-
|
|
806
|
-
|
|
807
|
-
# 📋
|
|
808
|
-
##
|
|
809
|
-
-
|
|
810
|
-
-
|
|
811
|
-
-
|
|
812
|
-
-
|
|
813
|
-
-
|
|
814
|
-
|
|
815
|
-
##
|
|
816
|
-
- 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
|
-
[
|
|
819
|
-
-
|
|
820
|
-
-
|
|
821
|
-
-
|
|
822
|
-
-
|
|
817
|
+
[详细的技术回答,包含:
|
|
818
|
+
- 实现细节
|
|
819
|
+
- 代码示例(如果相关)
|
|
820
|
+
- 缺失的信息(如果有)
|
|
821
|
+
- 相关技术概念]
|
|
823
822
|
|
|
824
|
-
- question: [
|
|
823
|
+
- question: [如果需要,提出后续问题]
|
|
825
824
|
answer: |
|
|
826
|
-
[
|
|
825
|
+
[额外的技术细节]
|
|
827
826
|
|
|
828
|
-
# 🔍
|
|
829
|
-
|
|
827
|
+
# 🔍 分析上下文
|
|
828
|
+
问题: {query}
|
|
830
829
|
|
|
831
|
-
|
|
830
|
+
相关代码文件(按相关性排序):
|
|
832
831
|
"""
|
|
833
832
|
|
|
834
|
-
#
|
|
835
|
-
available_count = self.max_token_count - get_context_token_count(prompt) - 1000 #
|
|
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
|
-
##
|
|
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
|
-
# ❗
|
|
865
|
-
1.
|
|
866
|
-
2.
|
|
867
|
-
3.
|
|
868
|
-
4.
|
|
869
|
-
5.
|
|
870
|
-
6.
|
|
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()
|