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.

Files changed (61) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +41 -27
  3. jarvis/jarvis_agent/builtin_input_handler.py +73 -0
  4. jarvis/{jarvis_code_agent → jarvis_agent}/file_input_handler.py +1 -1
  5. jarvis/jarvis_agent/main.py +1 -1
  6. jarvis/jarvis_agent/patch.py +461 -0
  7. jarvis/{jarvis_code_agent → jarvis_agent}/shell_input_handler.py +0 -1
  8. jarvis/jarvis_code_agent/code_agent.py +94 -89
  9. jarvis/jarvis_codebase/main.py +5 -5
  10. jarvis/jarvis_dev/main.py +833 -741
  11. jarvis/jarvis_git_squash/main.py +1 -1
  12. jarvis/jarvis_lsp/base.py +2 -26
  13. jarvis/jarvis_lsp/cpp.py +2 -14
  14. jarvis/jarvis_lsp/go.py +0 -13
  15. jarvis/jarvis_lsp/python.py +1 -30
  16. jarvis/jarvis_lsp/registry.py +10 -14
  17. jarvis/jarvis_lsp/rust.py +0 -12
  18. jarvis/jarvis_multi_agent/__init__.py +63 -53
  19. jarvis/jarvis_platform/registry.py +1 -2
  20. jarvis/jarvis_platform_manager/main.py +3 -3
  21. jarvis/jarvis_rag/main.py +1 -1
  22. jarvis/jarvis_tools/ask_codebase.py +40 -20
  23. jarvis/jarvis_tools/code_review.py +180 -143
  24. jarvis/jarvis_tools/create_code_agent.py +76 -72
  25. jarvis/jarvis_tools/create_sub_agent.py +31 -21
  26. jarvis/jarvis_tools/execute_shell.py +2 -2
  27. jarvis/jarvis_tools/execute_shell_script.py +1 -1
  28. jarvis/jarvis_tools/file_operation.py +2 -2
  29. jarvis/jarvis_tools/git_commiter.py +88 -68
  30. jarvis/jarvis_tools/lsp_find_definition.py +83 -67
  31. jarvis/jarvis_tools/lsp_find_references.py +62 -46
  32. jarvis/jarvis_tools/lsp_get_diagnostics.py +90 -74
  33. jarvis/jarvis_tools/methodology.py +3 -3
  34. jarvis/jarvis_tools/read_code.py +2 -2
  35. jarvis/jarvis_tools/search_web.py +18 -20
  36. jarvis/jarvis_tools/tool_generator.py +1 -1
  37. jarvis/jarvis_tools/treesitter_analyzer.py +331 -0
  38. jarvis/jarvis_treesitter/README.md +104 -0
  39. jarvis/jarvis_treesitter/__init__.py +20 -0
  40. jarvis/jarvis_treesitter/database.py +258 -0
  41. jarvis/jarvis_treesitter/example.py +115 -0
  42. jarvis/jarvis_treesitter/grammar_builder.py +182 -0
  43. jarvis/jarvis_treesitter/language.py +117 -0
  44. jarvis/jarvis_treesitter/symbol.py +31 -0
  45. jarvis/jarvis_treesitter/tools_usage.md +121 -0
  46. jarvis/jarvis_utils/git_utils.py +10 -2
  47. jarvis/jarvis_utils/input.py +3 -1
  48. jarvis/jarvis_utils/methodology.py +1 -1
  49. jarvis/jarvis_utils/output.py +2 -2
  50. jarvis/jarvis_utils/utils.py +3 -3
  51. {jarvis_ai_assistant-0.1.129.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/METADATA +2 -4
  52. jarvis_ai_assistant-0.1.131.dist-info/RECORD +85 -0
  53. jarvis/jarvis_code_agent/builtin_input_handler.py +0 -43
  54. jarvis/jarvis_code_agent/patch.py +0 -276
  55. jarvis/jarvis_tools/lsp_get_document_symbols.py +0 -87
  56. jarvis/jarvis_tools/lsp_prepare_rename.py +0 -130
  57. jarvis_ai_assistant-0.1.129.dist-info/RECORD +0 -78
  58. {jarvis_ai_assistant-0.1.129.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/LICENSE +0 -0
  59. {jarvis_ai_assistant-0.1.129.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/WHEEL +0 -0
  60. {jarvis_ai_assistant-0.1.129.dist-info → jarvis_ai_assistant-0.1.131.dist-info}/entry_points.txt +0 -0
  61. {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.jarvis_code_agent.builtin_input_handler import builtin_input_handler
10
- from jarvis.jarvis_code_agent.file_input_handler import file_input_handler
11
- from jarvis.jarvis_code_agent.shell_input_handler import shell_input_handler
12
- from jarvis.jarvis_code_agent.patch import PatchOutputHandler
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
- "lsp_prepare_rename"
36
+ "lsp_find_definition",
37
+ "treesitter_analyzer",
38
+ "code_review" # 新增代码审查工具
42
39
  ])
43
40
  code_system_prompt = """
44
- # 角色:高级代码工程师
45
- 精通安全、精确的代码修改,具有严格的验证流程。
46
-
47
- ## 核心原则
48
- 1. 安全第一:绝不破坏现有功能
49
- 2. 精准工程:最小化、针对性修改
50
- 3. 完整可追溯:记录所有决策
51
- 4. 验证驱动:在每个阶段进行验证
52
-
53
- ## 工具使用协议
54
- 1. 分析工具:
55
- - lsp_get_document_symbols:映射代码结构
56
- - lsp_find_references:理解使用模式
57
- - lsp_find_definition:追踪实现细节
58
-
59
- 2. 验证工具:
60
- - lsp_prepare_rename:安全重构检查
61
- - lsp_get_diagnostics:修改后检查
62
-
63
- 3. 系统工具:
64
- - execute_shell:用于git操作和grep搜索
65
- - ask_codebase:查询代码知识库
66
- - search_web:技术参考查找
67
-
68
- ## 工作流程(PDCA循环)
69
- 1. 计划:
70
- - 使用ask_user分析需求
71
- - 使用LSP工具映射现有代码
72
- - 使用find_references识别影响区域
73
- - 使用git创建回滚计划
74
-
75
- 2. 执行:
76
- - 在受保护的块中进行原子修改
77
- - 每次更改后自动运行lsp_get_diagnostics
78
- - 如果发现错误,使用lsp_find_references和lsp_find_definition进行即时修复
79
- - 每次更改后使用LSP验证语法
80
-
81
- 3. 检查:
82
- - 强制使用lsp_get_diagnostics进行完整诊断报告
83
- - 使用lsp_preprepare_rename验证所有重命名
84
- - 如果检测到错误,进入修复循环直到所有检查通过
85
-
86
- 4. 行动:
87
- - 使用git提交详细消息
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
- - 严格的代码范围验证(±3行缓冲区)
89
+ 2. **修改实施**:
90
+ - 单一职责变更
91
+ - 严格的范围验证
100
92
  - 接口兼容性检查
101
93
 
102
- 3. 验证清单:
103
- [ ] 执行lsp_get_diagnostics并确保零错误
104
- [ ] 使用lsp_find_references确认影响范围
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
- 1. 强制分析:
114
- - 修改前完整符号追踪
115
- - 跨文件影响分析
116
- - 依赖关系映射
117
-
118
- 2. 禁止操作:
119
- - 未通过lsp_get_diagnostics检查继续操作
120
- - 多个功能组合修改
121
- - 未经测试的接口修改
122
-
123
- 3. 紧急协议:
124
- - lsp_get_diagnostics出现错误时立即停止并回滚
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
- else:
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", "--soft", start_commit], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
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({})
@@ -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
  ```