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.

Files changed (75) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +165 -285
  3. jarvis/jarvis_agent/jarvis.py +143 -0
  4. jarvis/jarvis_agent/main.py +0 -2
  5. jarvis/jarvis_agent/patch.py +70 -48
  6. jarvis/jarvis_agent/shell_input_handler.py +1 -1
  7. jarvis/jarvis_code_agent/code_agent.py +169 -117
  8. jarvis/jarvis_dev/main.py +327 -626
  9. jarvis/jarvis_git_squash/main.py +10 -31
  10. jarvis/jarvis_lsp/base.py +0 -42
  11. jarvis/jarvis_lsp/cpp.py +0 -15
  12. jarvis/jarvis_lsp/go.py +0 -15
  13. jarvis/jarvis_lsp/python.py +0 -19
  14. jarvis/jarvis_lsp/registry.py +0 -62
  15. jarvis/jarvis_lsp/rust.py +0 -15
  16. jarvis/jarvis_multi_agent/__init__.py +19 -69
  17. jarvis/jarvis_multi_agent/main.py +43 -0
  18. jarvis/jarvis_platform/ai8.py +7 -32
  19. jarvis/jarvis_platform/base.py +2 -7
  20. jarvis/jarvis_platform/kimi.py +3 -144
  21. jarvis/jarvis_platform/ollama.py +54 -68
  22. jarvis/jarvis_platform/openai.py +0 -4
  23. jarvis/jarvis_platform/oyi.py +0 -75
  24. jarvis/jarvis_platform/registry.py +2 -16
  25. jarvis/jarvis_platform/yuanbao.py +264 -0
  26. jarvis/jarvis_rag/file_processors.py +138 -0
  27. jarvis/jarvis_rag/main.py +1305 -425
  28. jarvis/jarvis_tools/ask_codebase.py +216 -43
  29. jarvis/jarvis_tools/code_review.py +158 -113
  30. jarvis/jarvis_tools/create_sub_agent.py +0 -1
  31. jarvis/jarvis_tools/execute_python_script.py +58 -0
  32. jarvis/jarvis_tools/execute_shell.py +13 -26
  33. jarvis/jarvis_tools/execute_shell_script.py +1 -1
  34. jarvis/jarvis_tools/file_analyzer.py +282 -0
  35. jarvis/jarvis_tools/file_operation.py +1 -1
  36. jarvis/jarvis_tools/find_caller.py +278 -0
  37. jarvis/jarvis_tools/find_symbol.py +295 -0
  38. jarvis/jarvis_tools/function_analyzer.py +331 -0
  39. jarvis/jarvis_tools/git_commiter.py +5 -5
  40. jarvis/jarvis_tools/methodology.py +88 -53
  41. jarvis/jarvis_tools/project_analyzer.py +308 -0
  42. jarvis/jarvis_tools/rag.py +0 -5
  43. jarvis/jarvis_tools/read_code.py +24 -3
  44. jarvis/jarvis_tools/read_webpage.py +195 -81
  45. jarvis/jarvis_tools/registry.py +132 -11
  46. jarvis/jarvis_tools/search_web.py +22 -307
  47. jarvis/jarvis_tools/tool_generator.py +8 -10
  48. jarvis/jarvis_utils/__init__.py +1 -0
  49. jarvis/jarvis_utils/config.py +80 -76
  50. jarvis/jarvis_utils/embedding.py +344 -45
  51. jarvis/jarvis_utils/git_utils.py +9 -1
  52. jarvis/jarvis_utils/input.py +7 -6
  53. jarvis/jarvis_utils/methodology.py +384 -15
  54. jarvis/jarvis_utils/output.py +5 -3
  55. jarvis/jarvis_utils/utils.py +60 -8
  56. {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/METADATA +8 -16
  57. jarvis_ai_assistant-0.1.134.dist-info/RECORD +82 -0
  58. {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/entry_points.txt +4 -3
  59. jarvis/jarvis_codebase/__init__.py +0 -0
  60. jarvis/jarvis_codebase/main.py +0 -1011
  61. jarvis/jarvis_tools/lsp_find_definition.py +0 -150
  62. jarvis/jarvis_tools/lsp_find_references.py +0 -127
  63. jarvis/jarvis_tools/treesitter_analyzer.py +0 -331
  64. jarvis/jarvis_treesitter/README.md +0 -104
  65. jarvis/jarvis_treesitter/__init__.py +0 -20
  66. jarvis/jarvis_treesitter/database.py +0 -258
  67. jarvis/jarvis_treesitter/example.py +0 -115
  68. jarvis/jarvis_treesitter/grammar_builder.py +0 -182
  69. jarvis/jarvis_treesitter/language.py +0 -117
  70. jarvis/jarvis_treesitter/symbol.py +0 -31
  71. jarvis/jarvis_treesitter/tools_usage.md +0 -121
  72. jarvis_ai_assistant-0.1.131.dist-info/RECORD +0 -85
  73. {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/LICENSE +0 -0
  74. {jarvis_ai_assistant-0.1.131.dist-info → jarvis_ai_assistant-0.1.134.dist-info}/WHEEL +0 -0
  75. {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
- "lsp_find_references",
36
- "lsp_find_definition",
37
- "treesitter_analyzer",
38
- "code_review" # 新增代码审查工具
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
- - 通过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. **修改前要求**:
85
- - 完整的代码分析报告
86
- - 影响评估
87
- - 验证策略
88
-
89
- 2. **修改实施**:
90
- - 单一职责变更
91
- - 严格的范围验证
92
- - 接口兼容性检查
93
-
94
- 3. **验证清单**:
95
- - 运行lsp_get_diagnostics确保零错误
96
- - 使用lsp_find_references确认影响范围
97
-
98
- 4. **修改后流程**:
99
- - 代码审查模拟
100
- - 版本控制审计
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. 为每项更改包含清晰的理由说明
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
- self.agent = Agent(system_prompt=code_system_prompt,
135
- name="CodeAgent",
136
- auto_complete=False,
137
- is_sub_agent=False,
138
- use_methodology=False,
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=PlatformRegistry().get_codegen_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=False)
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
- # Interactive mode
218
- while True:
219
- try:
220
- user_input = get_multiline_input("请输入你的需求(输入空行退出):")
221
- if not user_input:
222
- break
223
- agent = CodeAgent()
224
- agent.run(user_input)
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)