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
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import re
|
|
2
1
|
import subprocess
|
|
3
2
|
import os
|
|
4
|
-
from typing import Any, Tuple
|
|
5
3
|
|
|
6
4
|
from yaspin import yaspin
|
|
7
5
|
|
|
8
6
|
from jarvis.jarvis_agent import Agent
|
|
9
|
-
from jarvis.
|
|
10
|
-
from jarvis.
|
|
11
|
-
from jarvis.
|
|
12
|
-
from jarvis.
|
|
7
|
+
from jarvis.jarvis_agent.builtin_input_handler import builtin_input_handler
|
|
8
|
+
from jarvis.jarvis_agent.file_input_handler import file_input_handler
|
|
9
|
+
from jarvis.jarvis_agent.shell_input_handler import shell_input_handler
|
|
10
|
+
from jarvis.jarvis_agent.patch import PatchOutputHandler
|
|
13
11
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
14
|
-
from jarvis.jarvis_tools.file_operation import FileOperationTool
|
|
15
12
|
from jarvis.jarvis_tools.git_commiter import GitCommitTool
|
|
16
13
|
|
|
17
14
|
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
@@ -34,96 +31,105 @@ class CodeAgent:
|
|
|
34
31
|
"create_code_agent",
|
|
35
32
|
"ask_user",
|
|
36
33
|
"ask_codebase",
|
|
37
|
-
"lsp_get_document_symbols",
|
|
38
34
|
"lsp_get_diagnostics",
|
|
39
35
|
"lsp_find_references",
|
|
40
|
-
"lsp_find_definition",
|
|
41
|
-
"
|
|
36
|
+
"lsp_find_definition",
|
|
37
|
+
"treesitter_analyzer",
|
|
38
|
+
"code_review" # 新增代码审查工具
|
|
42
39
|
])
|
|
43
40
|
code_system_prompt = """
|
|
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
|
-
1. 修改前要求:
|
|
41
|
+
# 专业代码工程师
|
|
42
|
+
|
|
43
|
+
## 身份与能力范围
|
|
44
|
+
- **角色定位**:精通精确、安全代码修改的高级代码工程师
|
|
45
|
+
- **核心能力**:代码分析、精准重构和系统化验证
|
|
46
|
+
- **知识领域**:软件架构、设计模式和特定语言的最佳实践
|
|
47
|
+
- **局限性**:复杂系统和特定领域知识需要明确的上下文支持
|
|
48
|
+
|
|
49
|
+
## 交互原则与策略
|
|
50
|
+
- **沟通风格**:清晰简洁的技术解释,为所有决策提供合理依据
|
|
51
|
+
- **呈现格式**:使用补丁格式展示结构化的代码变更及其上下文
|
|
52
|
+
- **主动引导**:在有益的情况下,提出超出即时需求的改进建议
|
|
53
|
+
- **特殊场景应对**:
|
|
54
|
+
- 对于模糊请求:在继续前提出澄清问题
|
|
55
|
+
- 对于高风险变更:提出带有验证步骤的渐进式方法
|
|
56
|
+
- 对于性能问题:平衡即时修复与长期架构考量
|
|
57
|
+
|
|
58
|
+
## 任务执行规范
|
|
59
|
+
### 分析阶段
|
|
60
|
+
- 通过lsp_find_references和lsp_find_definition追踪依赖关系
|
|
61
|
+
- 使用treesitter_analyzer深入分析代码结构和关系
|
|
62
|
+
- 在进行更改前识别潜在影响区域
|
|
63
|
+
- 为安全创建回滚计划
|
|
64
|
+
|
|
65
|
+
### 实施阶段
|
|
66
|
+
- 进行原子化、聚焦的最小范围更改
|
|
67
|
+
- 保持一致的代码风格和格式
|
|
68
|
+
- 每次重大更改后运行lsp_get_diagnostics
|
|
69
|
+
- 立即修复任何检测到的问题
|
|
70
|
+
- 确保代码修改后第一时间验证,优先修复错误而不是继续实现新功能
|
|
71
|
+
|
|
72
|
+
### 验证阶段
|
|
73
|
+
- 使用lsp_get_diagnostics进行全面诊断
|
|
74
|
+
- 检查相关代码中的意外副作用
|
|
75
|
+
- 确保必要的向后兼容性
|
|
76
|
+
|
|
77
|
+
### 文档阶段
|
|
78
|
+
- 为每项修改提供清晰的理由
|
|
79
|
+
- 在所有补丁描述中包含上下文
|
|
80
|
+
- 记录任何假设或约束条件
|
|
81
|
+
- 准备详细的提交信息
|
|
82
|
+
|
|
83
|
+
## 代码修改协议
|
|
84
|
+
1. **修改前要求**:
|
|
93
85
|
- 完整的代码分析报告
|
|
94
|
-
-
|
|
95
|
-
-
|
|
86
|
+
- 影响评估
|
|
87
|
+
- 验证策略
|
|
96
88
|
|
|
97
|
-
2.
|
|
98
|
-
-
|
|
99
|
-
-
|
|
89
|
+
2. **修改实施**:
|
|
90
|
+
- 单一职责变更
|
|
91
|
+
- 严格的范围验证
|
|
100
92
|
- 接口兼容性检查
|
|
101
93
|
|
|
102
|
-
3.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
[ ] 使用lsp_prepare_rename验证重命名安全性
|
|
94
|
+
3. **验证清单**:
|
|
95
|
+
- 运行lsp_get_diagnostics确保零错误
|
|
96
|
+
- 使用lsp_find_references确认影响范围
|
|
106
97
|
|
|
107
|
-
4.
|
|
98
|
+
4. **修改后流程**:
|
|
108
99
|
- 代码审查模拟
|
|
109
100
|
- 版本控制审计
|
|
110
|
-
-
|
|
111
|
-
|
|
112
|
-
##
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
101
|
+
- 更新变更文档
|
|
102
|
+
|
|
103
|
+
## 工具使用指南
|
|
104
|
+
- **分析工具**:
|
|
105
|
+
- lsp_find_references:用于理解使用模式
|
|
106
|
+
- lsp_find_definition:用于追踪实现细节
|
|
107
|
+
- treesitter_analyzer:用于高级代码分析,支持以下功能:
|
|
108
|
+
- find_symbol:查找符号定义位置
|
|
109
|
+
- find_references:查找符号的所有引用
|
|
110
|
+
- find_callers:查找函数的所有调用处
|
|
111
|
+
|
|
112
|
+
注意事项:
|
|
113
|
+
- 每次操作都会自动索引指定目录,无需单独执行索引步骤
|
|
114
|
+
- 适用于多种编程语言:Python, C, C++, Go, Rust 等
|
|
115
|
+
- 首次使用时会自动下载语法文件,可能需要一些时间
|
|
116
|
+
|
|
117
|
+
- **验证工具**:
|
|
118
|
+
- lsp_get_diagnostics:用于修改后检查
|
|
119
|
+
- code_review:用于代码审查
|
|
120
|
+
|
|
121
|
+
- **系统工具**:
|
|
122
|
+
- execute_shell:用于git操作和grep搜索
|
|
123
|
+
- ask_codebase:用于查询代码知识库
|
|
124
|
+
- search_web:用于技术参考查找
|
|
125
|
+
|
|
126
|
+
## 补丁格式要求
|
|
127
|
+
创建代码补丁时:
|
|
128
|
+
1. 包含足够的上下文(更改前后各3行)
|
|
129
|
+
2. 保留原始缩进和格式
|
|
130
|
+
3. 为新文件提供完整代码
|
|
131
|
+
4. 对于修改,保留周围未更改的代码
|
|
132
|
+
5. 为每项更改包含清晰的理由说明
|
|
127
133
|
"""
|
|
128
134
|
self.agent = Agent(system_prompt=code_system_prompt,
|
|
129
135
|
name="CodeAgent",
|
|
@@ -147,8 +153,7 @@ class CodeAgent:
|
|
|
147
153
|
with spinner.hidden():
|
|
148
154
|
git_commiter = GitCommitTool()
|
|
149
155
|
git_commiter.execute({})
|
|
150
|
-
|
|
151
|
-
spinner.text = "环境初始化完成"
|
|
156
|
+
spinner.text = "环境初始化完成"
|
|
152
157
|
spinner.ok("✅")
|
|
153
158
|
|
|
154
159
|
|
|
@@ -186,7 +191,7 @@ class CodeAgent:
|
|
|
186
191
|
if commits and user_confirm("是否接受以上提交记录?", True):
|
|
187
192
|
if len(commits) > 1 and user_confirm("是否要合并为一个更清晰的提交记录?", True):
|
|
188
193
|
# Reset to start commit
|
|
189
|
-
subprocess.run(["git", "reset", "--
|
|
194
|
+
subprocess.run(["git", "reset", "--mixed", start_commit], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
190
195
|
# Create new commit
|
|
191
196
|
git_commiter = GitCommitTool()
|
|
192
197
|
git_commiter.execute({})
|
jarvis/jarvis_codebase/main.py
CHANGED
|
@@ -78,7 +78,7 @@ class CodeBase:
|
|
|
78
78
|
|
|
79
79
|
def is_text_file(self, file_path: str):
|
|
80
80
|
try:
|
|
81
|
-
open(file_path, "r", encoding="utf-8").read()
|
|
81
|
+
open(file_path, "r", encoding="utf-8", errors="ignore").read()
|
|
82
82
|
return True
|
|
83
83
|
except Exception:
|
|
84
84
|
return False
|
|
@@ -233,7 +233,7 @@ class CodeBase:
|
|
|
233
233
|
return cached_vector
|
|
234
234
|
|
|
235
235
|
# Read the file content and combine information
|
|
236
|
-
content = open(file_path, "r", encoding="utf-8").read()[:self.max_token_count] # Limit the file content length
|
|
236
|
+
content = open(file_path, "r", encoding="utf-8", errors="ignore").read()[:self.max_token_count] # Limit the file content length
|
|
237
237
|
|
|
238
238
|
# Combine file information, including file content
|
|
239
239
|
combined_text = f"""
|
|
@@ -288,7 +288,7 @@ Content: {content}
|
|
|
288
288
|
|
|
289
289
|
md5 = get_file_md5(file_path)
|
|
290
290
|
|
|
291
|
-
content = open(file_path, "r", encoding="utf-8").read()
|
|
291
|
+
content = open(file_path, "r", encoding="utf-8", errors="ignore").read()
|
|
292
292
|
|
|
293
293
|
# Check if the file has already been processed and the content has not changed
|
|
294
294
|
if file_path in self.vector_cache:
|
|
@@ -565,7 +565,7 @@ Content: {content}
|
|
|
565
565
|
|
|
566
566
|
for path in initial_results:
|
|
567
567
|
try:
|
|
568
|
-
content = open(path, "r", encoding="utf-8").read()
|
|
568
|
+
content = open(path, "r", encoding="utf-8", errors="ignore").read()
|
|
569
569
|
# Truncate large files
|
|
570
570
|
if get_context_token_count(content) > max_file_length:
|
|
571
571
|
spinner.write(f"❌ 截断大文件: {path}")
|
|
@@ -861,7 +861,7 @@ Content: {content}
|
|
|
861
861
|
|
|
862
862
|
for path in files_from_codebase:
|
|
863
863
|
try:
|
|
864
|
-
content = open(path["file"], "r", encoding="utf-8").read()
|
|
864
|
+
content = open(path["file"], "r", encoding="utf-8", errors="ignore").read()
|
|
865
865
|
file_content = f"""
|
|
866
866
|
## 文件: {path["file"]}
|
|
867
867
|
```
|