jarvis-ai-assistant 0.1.131__py3-none-any.whl → 0.1.134__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 +165 -285
- jarvis/jarvis_agent/jarvis.py +143 -0
- jarvis/jarvis_agent/main.py +0 -2
- jarvis/jarvis_agent/patch.py +70 -48
- jarvis/jarvis_agent/shell_input_handler.py +1 -1
- jarvis/jarvis_code_agent/code_agent.py +169 -117
- jarvis/jarvis_dev/main.py +327 -626
- jarvis/jarvis_git_squash/main.py +10 -31
- jarvis/jarvis_lsp/base.py +0 -42
- jarvis/jarvis_lsp/cpp.py +0 -15
- jarvis/jarvis_lsp/go.py +0 -15
- jarvis/jarvis_lsp/python.py +0 -19
- jarvis/jarvis_lsp/registry.py +0 -62
- jarvis/jarvis_lsp/rust.py +0 -15
- jarvis/jarvis_multi_agent/__init__.py +19 -69
- jarvis/jarvis_multi_agent/main.py +43 -0
- jarvis/jarvis_platform/ai8.py +7 -32
- jarvis/jarvis_platform/base.py +2 -7
- jarvis/jarvis_platform/kimi.py +3 -144
- jarvis/jarvis_platform/ollama.py +54 -68
- jarvis/jarvis_platform/openai.py +0 -4
- jarvis/jarvis_platform/oyi.py +0 -75
- jarvis/jarvis_platform/registry.py +2 -16
- jarvis/jarvis_platform/yuanbao.py +264 -0
- jarvis/jarvis_rag/file_processors.py +138 -0
- jarvis/jarvis_rag/main.py +1305 -425
- jarvis/jarvis_tools/ask_codebase.py +216 -43
- jarvis/jarvis_tools/code_review.py +158 -113
- jarvis/jarvis_tools/create_sub_agent.py +0 -1
- jarvis/jarvis_tools/execute_python_script.py +58 -0
- jarvis/jarvis_tools/execute_shell.py +13 -26
- jarvis/jarvis_tools/execute_shell_script.py +1 -1
- jarvis/jarvis_tools/file_analyzer.py +282 -0
- jarvis/jarvis_tools/file_operation.py +1 -1
- jarvis/jarvis_tools/find_caller.py +278 -0
- jarvis/jarvis_tools/find_symbol.py +295 -0
- jarvis/jarvis_tools/function_analyzer.py +331 -0
- jarvis/jarvis_tools/git_commiter.py +5 -5
- jarvis/jarvis_tools/methodology.py +88 -53
- jarvis/jarvis_tools/project_analyzer.py +308 -0
- jarvis/jarvis_tools/rag.py +0 -5
- jarvis/jarvis_tools/read_code.py +24 -3
- jarvis/jarvis_tools/read_webpage.py +195 -81
- jarvis/jarvis_tools/registry.py +132 -11
- jarvis/jarvis_tools/search_web.py +22 -307
- jarvis/jarvis_tools/tool_generator.py +8 -10
- jarvis/jarvis_utils/__init__.py +1 -0
- jarvis/jarvis_utils/config.py +80 -76
- jarvis/jarvis_utils/embedding.py +344 -45
- jarvis/jarvis_utils/git_utils.py +9 -1
- jarvis/jarvis_utils/input.py +7 -6
- jarvis/jarvis_utils/methodology.py +384 -15
- jarvis/jarvis_utils/output.py +5 -3
- jarvis/jarvis_utils/utils.py +60 -8
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/METADATA +8 -16
- jarvis_ai_assistant-0.1.134.dist-info/RECORD +82 -0
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/entry_points.txt +4 -3
- jarvis/jarvis_codebase/__init__.py +0 -0
- jarvis/jarvis_codebase/main.py +0 -1011
- jarvis/jarvis_tools/lsp_find_definition.py +0 -150
- jarvis/jarvis_tools/lsp_find_references.py +0 -127
- jarvis/jarvis_tools/treesitter_analyzer.py +0 -331
- jarvis/jarvis_treesitter/README.md +0 -104
- jarvis/jarvis_treesitter/__init__.py +0 -20
- jarvis/jarvis_treesitter/database.py +0 -258
- jarvis/jarvis_treesitter/example.py +0 -115
- jarvis/jarvis_treesitter/grammar_builder.py +0 -182
- jarvis/jarvis_treesitter/language.py +0 -117
- jarvis/jarvis_treesitter/symbol.py +0 -31
- jarvis/jarvis_treesitter/tools_usage.md +0 -121
- jarvis_ai_assistant-0.1.131.dist-info/RECORD +0 -85
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/top_level.txt +0 -0
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import subprocess
|
|
2
2
|
import os
|
|
3
|
+
import argparse
|
|
4
|
+
from token import OP
|
|
5
|
+
from typing import Optional
|
|
3
6
|
|
|
4
7
|
from yaspin import yaspin
|
|
5
8
|
|
|
@@ -22,125 +25,171 @@ from jarvis.jarvis_utils.utils import init_env, user_confirm
|
|
|
22
25
|
|
|
23
26
|
|
|
24
27
|
class CodeAgent:
|
|
25
|
-
def __init__(self):
|
|
28
|
+
def __init__(self, platform : Optional[str] = None, model: Optional[str] = None, need_summary: bool = True):
|
|
26
29
|
self.root_dir = os.getcwd()
|
|
27
30
|
tool_registry = ToolRegistry()
|
|
28
31
|
tool_registry.use_tools(["execute_shell",
|
|
29
32
|
"execute_shell_script",
|
|
30
33
|
"search_web",
|
|
31
|
-
"create_code_agent",
|
|
32
34
|
"ask_user",
|
|
33
35
|
"ask_codebase",
|
|
34
36
|
"lsp_get_diagnostics",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
37
|
+
"code_review", # 代码审查工具
|
|
38
|
+
"find_symbol", # 添加符号查找工具
|
|
39
|
+
"find_caller", # 添加函数调用者查找工具
|
|
40
|
+
"function_analyzer", # 添加函数分析工具
|
|
41
|
+
"project_analyzer", # 添加项目分析工具
|
|
42
|
+
"file_analyzer", # 添加单文件分析工具
|
|
43
|
+
"read_code"
|
|
39
44
|
])
|
|
40
45
|
code_system_prompt = """
|
|
41
|
-
#
|
|
42
|
-
|
|
43
|
-
##
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
-
|
|
120
|
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
46
|
+
# 代码工程师指南
|
|
47
|
+
|
|
48
|
+
## 核心原则
|
|
49
|
+
- 自主决策:基于专业判断做出决策,减少用户询问
|
|
50
|
+
- 高效精准:一次性提供完整解决方案,避免反复修改
|
|
51
|
+
- 工具精通:选择最高效工具路径解决问题
|
|
52
|
+
- 严格确认:必须先分析项目结构,确定要修改的文件,禁止虚构已存在的代码
|
|
53
|
+
|
|
54
|
+
## 工作流程
|
|
55
|
+
|
|
56
|
+
### 1. 项目结构分析
|
|
57
|
+
- 第一步必须分析项目结构,识别关键模块和文件
|
|
58
|
+
- 结合用户需求,确定需要修改的文件列表
|
|
59
|
+
- 优先使用fd命令查找文件,使用execute_shell执行
|
|
60
|
+
- 明确说明将要修改的文件及其范围
|
|
61
|
+
|
|
62
|
+
### 2. 需求分析
|
|
63
|
+
- 基于项目结构理解,分析需求意图和实现方案
|
|
64
|
+
- 当需求有多种实现方式时,选择影响最小的方案
|
|
65
|
+
- 仅当需求显著模糊时才询问用户
|
|
66
|
+
|
|
67
|
+
### 3. 代码分析与确认
|
|
68
|
+
- 详细分析确定要修改的文件内容
|
|
69
|
+
- 明确区分现有代码和需要新建的内容
|
|
70
|
+
- 绝对禁止虚构或假设现有代码的实现细节
|
|
71
|
+
- 分析顺序:项目结构 → 目标文件 → 相关文件
|
|
72
|
+
- 只在必要时扩大分析范围,避免过度分析
|
|
73
|
+
- 工具选择:
|
|
74
|
+
| 分析需求 | 首选工具 | 备选工具 |
|
|
75
|
+
|---------|---------|----------|
|
|
76
|
+
| 项目结构 | fd (通过execute_shell) | project_analyzer(仅在必要时) |
|
|
77
|
+
| 文件内容 | read_code | file_analyzer(仅在必要时) |
|
|
78
|
+
| 查找引用 | rg (通过execute_shell) | find_symbol(仅在必要时) |
|
|
79
|
+
| 查找定义 | rg (通过execute_shell) | find_symbol(仅在必要时) |
|
|
80
|
+
| 函数调用者 | rg (通过execute_shell) | find_caller(仅在必要时) |
|
|
81
|
+
| 函数分析 | read_code + rg | function_analyzer(仅在必要时) |
|
|
82
|
+
| 整体分析 | execute_shell_script | ask_codebase(仅在必要时) |
|
|
83
|
+
| 代码质量检查 | execute_shell | code_review(仅在必要时) |
|
|
84
|
+
| 统计代码行数 | loc (通过execute_shell) | - |
|
|
85
|
+
|
|
86
|
+
### 4. 方案设计
|
|
87
|
+
- 确定最小变更方案,保持代码结构
|
|
88
|
+
- 变更类型处理:
|
|
89
|
+
- 修改现有文件:必须先确认文件存在及其内容
|
|
90
|
+
- 创建新文件:可以根据需求创建,但要符合项目结构和风格
|
|
91
|
+
- 变更规模处理:
|
|
92
|
+
- ≤50行:一次性完成所有修改
|
|
93
|
+
- 50-200行:按功能模块分组
|
|
94
|
+
- >200行:按功能拆分,但尽量减少提交次数
|
|
95
|
+
|
|
96
|
+
### 5. 实施修改
|
|
97
|
+
- 遵循"先读后写"原则,在修改已有代码前,必须已经读取了对应文件
|
|
98
|
+
- 保持代码风格一致性
|
|
99
|
+
- 自动匹配项目现有命名风格
|
|
100
|
+
- 允许创建新文件和结构,但不得假设或虚构现有代码
|
|
101
|
+
|
|
102
|
+
### 6. 验证
|
|
103
|
+
- 修改后自动验证:
|
|
104
|
+
1. 优先使用execute_shell运行相关静态检查命令(如pylint、flake8或单元测试)
|
|
105
|
+
2. 只有在shell命令不足时才使用lsp_get_diagnostics
|
|
106
|
+
3. 只有在特殊情况下才使用code_review
|
|
107
|
+
- 发现问题自动修复,无需用户指导
|
|
108
|
+
|
|
109
|
+
## 专用工具简介
|
|
110
|
+
仅在必要时使用以下专用工具:
|
|
111
|
+
|
|
112
|
+
- **project_analyzer**: 项目整体结构分析,仅在fd命令无法满足需求时使用
|
|
113
|
+
- **file_analyzer**: 单文件深度分析,应优先使用read_code替代
|
|
114
|
+
- **find_caller**: 函数调用者查找,应优先使用rg命令替代
|
|
115
|
+
- **find_symbol**: 符号引用查找,应优先使用rg命令替代
|
|
116
|
+
- **function_analyzer**: 函数实现分析,应优先使用read_code和rg组合替代
|
|
117
|
+
- **ask_codebase**: 代码库整体查询,应优先使用fd、rg和read_code组合替代
|
|
118
|
+
- **code_review**: 代码质量检查,应优先使用语言特定的lint工具替代
|
|
119
|
+
|
|
120
|
+
## Shell命令优先策略
|
|
121
|
+
|
|
122
|
+
### 优先使用的Shell命令
|
|
123
|
+
- **项目结构分析**:
|
|
124
|
+
- `fd -t f -e py` 查找所有Python文件
|
|
125
|
+
- `fd -t f -e js -e ts` 查找所有JavaScript/TypeScript文件
|
|
126
|
+
- `fd -t d` 列出所有目录
|
|
127
|
+
- `fd -t f -e java -e kt` 查找所有Java/Kotlin文件
|
|
128
|
+
- `fd -t f -e go` 查找所有Go文件
|
|
129
|
+
- `fd -t f -e rs` 查找所有Rust文件
|
|
130
|
+
- `fd -t f -e c -e cpp -e h -e hpp` 查找所有C/C++文件
|
|
131
|
+
|
|
132
|
+
- **代码内容搜索**:
|
|
133
|
+
- `rg "pattern" --type py` 在Python文件中搜索
|
|
134
|
+
- `rg "pattern" --type js` 在JavaScript文件中搜索
|
|
135
|
+
- `rg "pattern" --type java` 在Java文件中搜索
|
|
136
|
+
- `rg "pattern" --type c` 在C文件中搜索
|
|
137
|
+
- `rg "class ClassName"` 查找类定义
|
|
138
|
+
- `rg "func|function|def" -g "*.py" -g "*.js" -g "*.go" -g "*.rs"` 查找函数定义
|
|
139
|
+
- `rg -w "word"` 精确匹配单词
|
|
140
|
+
|
|
141
|
+
- **代码统计分析**:
|
|
142
|
+
- `loc <file_path>` 统计单个文件
|
|
143
|
+
- `loc --include="*.py"` 统计所有Python文件
|
|
144
|
+
- `loc --include="*.js" --include="*.ts"` 统计所有JavaScript/TypeScript文件
|
|
145
|
+
- `loc --exclude="test"` 排除测试文件
|
|
146
|
+
- `loc --sort=code` 按代码量排序
|
|
147
|
+
|
|
148
|
+
- **代码质量检查**:
|
|
149
|
+
- Python: `pylint <file_path>`, `flake8 <file_path>`
|
|
150
|
+
- JavaScript: `eslint <file_path>`
|
|
151
|
+
- TypeScript: `tsc --noEmit <file_path>`
|
|
152
|
+
- Java: `checkstyle <file_path>`
|
|
153
|
+
- Go: `go vet <file_path>`
|
|
154
|
+
- Rust: `cargo clippy`
|
|
155
|
+
- C/C++: `cppcheck <file_path>`
|
|
156
|
+
|
|
157
|
+
- **整体代码分析**:
|
|
158
|
+
- 使用execute_shell_script编写和执行脚本,批量分析多个文件
|
|
159
|
+
- 简单脚本示例:`find . -name "*.py" | xargs pylint`
|
|
160
|
+
- 使用多工具组合:`fd -e py | xargs pylint`
|
|
161
|
+
|
|
162
|
+
### read_code工具使用
|
|
163
|
+
读取文件应优先使用read_code工具,而非shell命令:
|
|
164
|
+
- 完整读取:使用read_code读取整个文件内容
|
|
165
|
+
- 部分读取:使用read_code指定行范围
|
|
166
|
+
- 大文件处理:对大型文件使用read_code指定行范围,避免全部加载
|
|
167
|
+
|
|
168
|
+
### 仅在命令行工具不足时使用专用工具
|
|
169
|
+
只有当fd、rg、loc和read_code工具无法获取足够信息时,才考虑使用专用工具(ask_codebase、code_review等)。在每次使用专用工具前,应先尝试使用上述工具获取所需信息。
|
|
170
|
+
|
|
171
|
+
### 注意事项
|
|
172
|
+
- read_code比cat或grep更适合阅读代码
|
|
173
|
+
- rg比grep更快更强大,应优先使用
|
|
174
|
+
- fd比find更快更易用,应优先使用
|
|
175
|
+
- loc比wc -l提供更多代码统计信息,应优先使用
|
|
176
|
+
- 针对不同编程语言选择对应的代码质量检查工具
|
|
133
177
|
"""
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
178
|
+
# Dynamically add ask_codebase based on task complexity if really needed
|
|
179
|
+
# 处理platform参数
|
|
180
|
+
platform_instance = (PlatformRegistry().create_platform(platform)
|
|
181
|
+
if platform
|
|
182
|
+
else PlatformRegistry().get_normal_platform())
|
|
183
|
+
if model:
|
|
184
|
+
platform_instance.set_model_name(model) # type: ignore
|
|
185
|
+
|
|
186
|
+
self.agent = Agent(system_prompt=code_system_prompt,
|
|
187
|
+
name="CodeAgent",
|
|
188
|
+
auto_complete=False,
|
|
139
189
|
output_handler=[tool_registry, PatchOutputHandler()],
|
|
140
|
-
platform=
|
|
141
|
-
record_methodology=False,
|
|
190
|
+
platform=platform_instance,
|
|
142
191
|
input_handler=[shell_input_handler, file_input_handler, builtin_input_handler],
|
|
143
|
-
need_summary=
|
|
192
|
+
need_summary=need_summary)
|
|
144
193
|
|
|
145
194
|
|
|
146
195
|
|
|
@@ -209,22 +258,25 @@ def main():
|
|
|
209
258
|
# Add argument parser
|
|
210
259
|
init_env()
|
|
211
260
|
|
|
261
|
+
parser = argparse.ArgumentParser(description='Jarvis Code Agent')
|
|
262
|
+
parser.add_argument('-p', '--platform', type=str, help='Target platform name', default=None)
|
|
263
|
+
parser.add_argument('-m', '--model', type=str, help='Model name to use', default=None)
|
|
264
|
+
args = parser.parse_args()
|
|
265
|
+
|
|
212
266
|
curr_dir = os.getcwd()
|
|
213
267
|
git_dir = find_git_root(curr_dir)
|
|
214
268
|
PrettyOutput.print(f"当前目录: {git_dir}", OutputType.INFO)
|
|
215
269
|
|
|
216
270
|
try:
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
except Exception as e:
|
|
227
|
-
PrettyOutput.print(f"错误: {str(e)}", OutputType.ERROR)
|
|
271
|
+
try:
|
|
272
|
+
user_input = get_multiline_input("请输入你的需求(输入空行退出):")
|
|
273
|
+
if not user_input:
|
|
274
|
+
return 0
|
|
275
|
+
agent = CodeAgent(platform=args.platform, model=args.model, need_summary=False)
|
|
276
|
+
agent.run(user_input)
|
|
277
|
+
|
|
278
|
+
except Exception as e:
|
|
279
|
+
PrettyOutput.print(f"错误: {str(e)}", OutputType.ERROR)
|
|
228
280
|
|
|
229
281
|
except Exception as e:
|
|
230
282
|
PrettyOutput.print(f"初始化错误: {str(e)}", OutputType.ERROR)
|