jarvis-ai-assistant 0.1.129__py3-none-any.whl → 0.1.131__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 +41 -27
- jarvis/jarvis_agent/builtin_input_handler.py +73 -0
- jarvis/{jarvis_code_agent → jarvis_agent}/file_input_handler.py +1 -1
- jarvis/jarvis_agent/main.py +1 -1
- jarvis/jarvis_agent/patch.py +461 -0
- jarvis/{jarvis_code_agent → jarvis_agent}/shell_input_handler.py +0 -1
- jarvis/jarvis_code_agent/code_agent.py +94 -89
- jarvis/jarvis_codebase/main.py +5 -5
- jarvis/jarvis_dev/main.py +833 -741
- jarvis/jarvis_git_squash/main.py +1 -1
- jarvis/jarvis_lsp/base.py +2 -26
- jarvis/jarvis_lsp/cpp.py +2 -14
- jarvis/jarvis_lsp/go.py +0 -13
- jarvis/jarvis_lsp/python.py +1 -30
- jarvis/jarvis_lsp/registry.py +10 -14
- jarvis/jarvis_lsp/rust.py +0 -12
- jarvis/jarvis_multi_agent/__init__.py +63 -53
- jarvis/jarvis_platform/registry.py +1 -2
- jarvis/jarvis_platform_manager/main.py +3 -3
- jarvis/jarvis_rag/main.py +1 -1
- jarvis/jarvis_tools/ask_codebase.py +40 -20
- jarvis/jarvis_tools/code_review.py +180 -143
- jarvis/jarvis_tools/create_code_agent.py +76 -72
- jarvis/jarvis_tools/create_sub_agent.py +31 -21
- jarvis/jarvis_tools/execute_shell.py +2 -2
- jarvis/jarvis_tools/execute_shell_script.py +1 -1
- jarvis/jarvis_tools/file_operation.py +2 -2
- jarvis/jarvis_tools/git_commiter.py +88 -68
- jarvis/jarvis_tools/lsp_find_definition.py +83 -67
- jarvis/jarvis_tools/lsp_find_references.py +62 -46
- jarvis/jarvis_tools/lsp_get_diagnostics.py +90 -74
- jarvis/jarvis_tools/methodology.py +3 -3
- jarvis/jarvis_tools/read_code.py +2 -2
- jarvis/jarvis_tools/search_web.py +18 -20
- jarvis/jarvis_tools/tool_generator.py +1 -1
- jarvis/jarvis_tools/treesitter_analyzer.py +331 -0
- jarvis/jarvis_treesitter/README.md +104 -0
- jarvis/jarvis_treesitter/__init__.py +20 -0
- jarvis/jarvis_treesitter/database.py +258 -0
- jarvis/jarvis_treesitter/example.py +115 -0
- jarvis/jarvis_treesitter/grammar_builder.py +182 -0
- jarvis/jarvis_treesitter/language.py +117 -0
- jarvis/jarvis_treesitter/symbol.py +31 -0
- jarvis/jarvis_treesitter/tools_usage.md +121 -0
- jarvis/jarvis_utils/git_utils.py +10 -2
- jarvis/jarvis_utils/input.py +3 -1
- jarvis/jarvis_utils/methodology.py +1 -1
- jarvis/jarvis_utils/output.py +2 -2
- jarvis/jarvis_utils/utils.py +3 -3
- {jarvis_ai_assistant-0.1.129.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/METADATA +2 -4
- jarvis_ai_assistant-0.1.131.dist-info/RECORD +85 -0
- jarvis/jarvis_code_agent/builtin_input_handler.py +0 -43
- jarvis/jarvis_code_agent/patch.py +0 -276
- jarvis/jarvis_tools/lsp_get_document_symbols.py +0 -87
- jarvis/jarvis_tools/lsp_prepare_rename.py +0 -130
- jarvis_ai_assistant-0.1.129.dist-info/RECORD +0 -78
- {jarvis_ai_assistant-0.1.129.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.129.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.129.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.129.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/top_level.txt +0 -0
jarvis/__init__.py
CHANGED
jarvis/jarvis_agent/__init__.py
CHANGED
|
@@ -6,6 +6,10 @@ import yaml
|
|
|
6
6
|
from yaspin import yaspin
|
|
7
7
|
|
|
8
8
|
from jarvis.jarvis_agent.output_handler import OutputHandler
|
|
9
|
+
from jarvis.jarvis_agent.builtin_input_handler import builtin_input_handler
|
|
10
|
+
from jarvis.jarvis_agent.file_input_handler import file_input_handler
|
|
11
|
+
from jarvis.jarvis_agent.patch import PatchOutputHandler
|
|
12
|
+
from jarvis.jarvis_agent.shell_input_handler import shell_input_handler
|
|
9
13
|
from jarvis.jarvis_platform.base import BasePlatform
|
|
10
14
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
11
15
|
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
@@ -23,13 +27,25 @@ import os
|
|
|
23
27
|
class Agent:
|
|
24
28
|
|
|
25
29
|
def set_summary_prompt(self, summary_prompt: str):
|
|
26
|
-
"""
|
|
30
|
+
"""设置任务完成时的总结提示模板。
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
summary_prompt:
|
|
32
|
+
参数:
|
|
33
|
+
summary_prompt: 用于生成任务总结的提示模板
|
|
30
34
|
"""
|
|
31
35
|
self.summary_prompt = summary_prompt
|
|
32
36
|
|
|
37
|
+
def clear(self):
|
|
38
|
+
"""清除当前对话历史,保留系统消息。
|
|
39
|
+
|
|
40
|
+
该方法将:
|
|
41
|
+
1. 调用模型的delete_chat方法清除对话历史
|
|
42
|
+
2. 重置对话长度计数器
|
|
43
|
+
3. 清空当前提示
|
|
44
|
+
"""
|
|
45
|
+
self.model.delete_chat() # type: ignore
|
|
46
|
+
self.conversation_length = 0
|
|
47
|
+
self.prompt = ""
|
|
48
|
+
|
|
33
49
|
def __del__(self):
|
|
34
50
|
delete_agent(self.name)
|
|
35
51
|
|
|
@@ -126,7 +142,7 @@ class Agent:
|
|
|
126
142
|
# 添加工具使用总结
|
|
127
143
|
action_prompt += """
|
|
128
144
|
# ❗ 重要操作使用规则
|
|
129
|
-
1.
|
|
145
|
+
1. 一次对话只能使用一个操作,否则会出错
|
|
130
146
|
2. 严格按照每个操作的格式执行
|
|
131
147
|
3. 等待操作结果后再进行下一个操作
|
|
132
148
|
4. 处理完结果后再调用新的操作
|
|
@@ -152,23 +168,23 @@ class Agent:
|
|
|
152
168
|
|
|
153
169
|
|
|
154
170
|
|
|
155
|
-
def _call_model(self, message: str) -> str:
|
|
156
|
-
"""
|
|
171
|
+
def _call_model(self, message: str) -> str:
|
|
172
|
+
"""调用AI模型并实现重试逻辑。
|
|
157
173
|
|
|
158
|
-
|
|
159
|
-
message:
|
|
174
|
+
参数:
|
|
175
|
+
message: 输入给模型的消息
|
|
160
176
|
|
|
161
|
-
|
|
162
|
-
str:
|
|
177
|
+
返回:
|
|
178
|
+
str: 模型的响应
|
|
163
179
|
|
|
164
|
-
|
|
165
|
-
|
|
180
|
+
注意:
|
|
181
|
+
将使用指数退避重试,最多重试30秒
|
|
166
182
|
"""
|
|
167
183
|
for handler in self.input_handler:
|
|
168
184
|
message, need_return = handler(message, self)
|
|
169
185
|
if need_return:
|
|
170
186
|
return message
|
|
171
|
-
|
|
187
|
+
print("🤖 模型思考:")
|
|
172
188
|
return self.model.chat_until_success(message) # type: ignore
|
|
173
189
|
|
|
174
190
|
|
|
@@ -203,6 +219,8 @@ class Agent:
|
|
|
203
219
|
try:
|
|
204
220
|
with spinner.hidden():
|
|
205
221
|
summary = self._call_model(self.prompt + "\n" + prompt)
|
|
222
|
+
|
|
223
|
+
self.model.delete_chat() # type: ignore
|
|
206
224
|
|
|
207
225
|
# 清空当前对话历史,但保留系统消息
|
|
208
226
|
self.conversation_length = 0 # Reset conversation length
|
|
@@ -352,16 +370,16 @@ class Agent:
|
|
|
352
370
|
return f"Task failed: {str(e)}"
|
|
353
371
|
|
|
354
372
|
def _clear_history(self):
|
|
355
|
-
"""
|
|
373
|
+
"""清空对话历史但保留系统提示。
|
|
356
374
|
|
|
357
|
-
|
|
358
|
-
1.
|
|
359
|
-
2.
|
|
360
|
-
3.
|
|
375
|
+
该方法将:
|
|
376
|
+
1. 清空当前提示
|
|
377
|
+
2. 重置模型状态
|
|
378
|
+
3. 重置对话长度计数器
|
|
361
379
|
"""
|
|
362
380
|
self.prompt = ""
|
|
363
381
|
self.model.reset() # type: ignore
|
|
364
|
-
self.conversation_length = 0 #
|
|
382
|
+
self.conversation_length = 0 # 重置对话长度
|
|
365
383
|
|
|
366
384
|
|
|
367
385
|
|
|
@@ -375,7 +393,7 @@ def _load_tasks() -> dict:
|
|
|
375
393
|
if os.path.exists(user_jarvis):
|
|
376
394
|
with yaspin(text=f"从{user_jarvis}加载预定义任务...", color="cyan") as spinner:
|
|
377
395
|
try:
|
|
378
|
-
with open(user_jarvis, "r", encoding="utf-8") as f:
|
|
396
|
+
with open(user_jarvis, "r", encoding="utf-8", errors="ignore") as f:
|
|
379
397
|
user_tasks = yaml.safe_load(f)
|
|
380
398
|
|
|
381
399
|
if isinstance(user_tasks, dict):
|
|
@@ -393,7 +411,7 @@ def _load_tasks() -> dict:
|
|
|
393
411
|
if os.path.exists(".jarvis/pre-command"):
|
|
394
412
|
with yaspin(text=f"从{os.path.abspath('.jarvis/pre-command')}加载预定义任务...", color="cyan") as spinner:
|
|
395
413
|
try:
|
|
396
|
-
with open(".jarvis/pre-command", "r", encoding="utf-8") as f:
|
|
414
|
+
with open(".jarvis/pre-command", "r", encoding="utf-8", errors="ignore") as f:
|
|
397
415
|
local_tasks = yaml.safe_load(f)
|
|
398
416
|
|
|
399
417
|
if isinstance(local_tasks, dict):
|
|
@@ -467,10 +485,8 @@ origin_agent_system_prompt = """
|
|
|
467
485
|
|
|
468
486
|
# 🔥 绝对行动要求
|
|
469
487
|
1. 每个响应必须包含且仅包含一个工具调用
|
|
470
|
-
2.
|
|
488
|
+
2. 唯一例外:任务结束
|
|
471
489
|
3. 空响应会触发致命错误
|
|
472
|
-
4. 不能处于"等待用户输入"状态
|
|
473
|
-
5. 任何行动都不能使用完成命令
|
|
474
490
|
|
|
475
491
|
# 🚫 违规示例
|
|
476
492
|
- 没有工具调用的分析 → 永久挂起
|
|
@@ -500,8 +516,6 @@ origin_agent_system_prompt = """
|
|
|
500
516
|
4. 任务完成
|
|
501
517
|
- 验证目标完成情况
|
|
502
518
|
- 如有价值则记录方法论
|
|
503
|
-
- 使用完成命令结束任务
|
|
504
|
-
→ 必须使用 <!!!COMPLETE!!!>
|
|
505
519
|
|
|
506
520
|
# 📑 方法论模板
|
|
507
521
|
```markdown
|
|
@@ -553,7 +567,7 @@ def main():
|
|
|
553
567
|
|
|
554
568
|
try:
|
|
555
569
|
# 获取全局模型实例
|
|
556
|
-
agent = Agent(system_prompt=origin_agent_system_prompt, platform=args.platform, model_name=args.model, output_handler=[ToolRegistry()])
|
|
570
|
+
agent = Agent(system_prompt=origin_agent_system_prompt, platform=args.platform, model_name=args.model, input_handler=[file_input_handler, shell_input_handler, builtin_input_handler] ,output_handler=[ToolRegistry(), PatchOutputHandler()])
|
|
557
571
|
|
|
558
572
|
# 加载预定义任务
|
|
559
573
|
tasks = _load_tasks()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import Any, Tuple
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def builtin_input_handler(user_input: str, agent: Any) -> Tuple[str, bool]:
|
|
7
|
+
"""
|
|
8
|
+
处理内置的特殊输入标记,并追加相应的提示词
|
|
9
|
+
|
|
10
|
+
参数:
|
|
11
|
+
user_input: 用户输入
|
|
12
|
+
agent: 代理对象
|
|
13
|
+
|
|
14
|
+
返回:
|
|
15
|
+
Tuple[str, bool]: 处理后的输入和是否需要进一步处理
|
|
16
|
+
"""
|
|
17
|
+
# 查找特殊标记
|
|
18
|
+
special_tags = re.findall(r"'<([^>]+)>'", user_input)
|
|
19
|
+
|
|
20
|
+
if not special_tags:
|
|
21
|
+
return user_input, False
|
|
22
|
+
|
|
23
|
+
# 使用集合去重
|
|
24
|
+
processed_tags = set()
|
|
25
|
+
# 处理每个标记
|
|
26
|
+
for tag in special_tags:
|
|
27
|
+
if tag in processed_tags:
|
|
28
|
+
continue
|
|
29
|
+
processed_tags.add(tag)
|
|
30
|
+
|
|
31
|
+
if tag == "CodeBase":
|
|
32
|
+
user_input = user_input.replace(f"'<{tag}>'", "")
|
|
33
|
+
user_input += """
|
|
34
|
+
请使用ask_codebase工具查询代码库,可以使用的提问格式包括:
|
|
35
|
+
1. 与xxx功能相关的文件有哪些?
|
|
36
|
+
2. 要实现xxx,应该要修改哪些文件?
|
|
37
|
+
3. xxx功能是怎么实现的?
|
|
38
|
+
4. xxx模块的入口函数是什么?
|
|
39
|
+
5. xxx功能的测试用例在哪里?
|
|
40
|
+
"""
|
|
41
|
+
elif tag == "Web":
|
|
42
|
+
user_input = user_input.replace(f"'<{tag}>'", "")
|
|
43
|
+
user_input += """
|
|
44
|
+
请使用search_web工具进行网页搜索,可以使用的提问格式包括:
|
|
45
|
+
1. xxx技术的最新发展是什么?
|
|
46
|
+
2. xxx框架的官方文档在哪里?
|
|
47
|
+
3. xxx库的GitHub仓库地址是什么?
|
|
48
|
+
4. xxx问题的解决方案有哪些?
|
|
49
|
+
5. xxx概念的详细解释是什么?
|
|
50
|
+
"""
|
|
51
|
+
elif tag == "RAG":
|
|
52
|
+
user_input = user_input.replace(f"'<{tag}>'", "")
|
|
53
|
+
user_input += """
|
|
54
|
+
请使用rag工具进行知识库检索,可以使用的提问格式包括:
|
|
55
|
+
1. 关于xxx的知识点有哪些?
|
|
56
|
+
2. xxx的最佳实践是什么?
|
|
57
|
+
3. xxx的实现方案有哪些?
|
|
58
|
+
4. xxx的相关案例有哪些?
|
|
59
|
+
5. xxx的技术细节是什么?
|
|
60
|
+
"""
|
|
61
|
+
elif tag == "Summary":
|
|
62
|
+
user_input = user_input.replace(f"'<{tag}>'", "")
|
|
63
|
+
agent._summarize_and_clear_history()
|
|
64
|
+
if not user_input.strip():
|
|
65
|
+
return "", True
|
|
66
|
+
elif tag == "Clear":
|
|
67
|
+
user_input = user_input.replace(f"'<{tag}>'", "")
|
|
68
|
+
agent.clear()
|
|
69
|
+
if not user_input.strip():
|
|
70
|
+
return "", True
|
|
71
|
+
# 移除对未知标记的警告输出
|
|
72
|
+
|
|
73
|
+
return user_input, False
|
|
@@ -30,7 +30,7 @@ def file_input_handler(user_input: str, agent: Any) -> Tuple[str, bool]:
|
|
|
30
30
|
|
|
31
31
|
# Handle special values and Python-style negative indices
|
|
32
32
|
try:
|
|
33
|
-
with open(file_path, 'r', encoding='utf-8') as f:
|
|
33
|
+
with open(file_path, 'r', encoding='utf-8', errors="ignore") as f:
|
|
34
34
|
total_lines = len(f.readlines())
|
|
35
35
|
except FileNotFoundError:
|
|
36
36
|
PrettyOutput.print(f"文件不存在: {file_path}", OutputType.WARNING)
|
jarvis/jarvis_agent/main.py
CHANGED
|
@@ -23,7 +23,7 @@ def load_config(config_path: str) -> dict:
|
|
|
23
23
|
PrettyOutput.print(f"配置文件 {config_path} 不存在,使用默认配置", OutputType.WARNING)
|
|
24
24
|
return {}
|
|
25
25
|
|
|
26
|
-
with open(config_path, 'r', encoding='utf-8') as f:
|
|
26
|
+
with open(config_path, 'r', encoding='utf-8', errors="ignore") as f:
|
|
27
27
|
try:
|
|
28
28
|
config = yaml.safe_load(f)
|
|
29
29
|
return config if config else {}
|