jarvis-ai-assistant 0.1.207__py3-none-any.whl → 0.1.209__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.
Files changed (42) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +63 -103
  3. jarvis/jarvis_agent/edit_file_handler.py +43 -47
  4. jarvis/jarvis_agent/jarvis.py +33 -39
  5. jarvis/jarvis_code_agent/code_agent.py +74 -30
  6. jarvis/jarvis_code_agent/lint.py +6 -6
  7. jarvis/jarvis_code_analysis/code_review.py +164 -175
  8. jarvis/jarvis_data/config_schema.json +0 -25
  9. jarvis/jarvis_git_utils/git_commiter.py +148 -153
  10. jarvis/jarvis_methodology/main.py +70 -81
  11. jarvis/jarvis_platform/base.py +21 -17
  12. jarvis/jarvis_platform/kimi.py +59 -64
  13. jarvis/jarvis_platform/tongyi.py +118 -131
  14. jarvis/jarvis_platform/yuanbao.py +117 -122
  15. jarvis/jarvis_platform_manager/main.py +102 -502
  16. jarvis/jarvis_platform_manager/service.py +432 -0
  17. jarvis/jarvis_smart_shell/main.py +99 -33
  18. jarvis/jarvis_tools/ask_user.py +0 -1
  19. jarvis/jarvis_tools/edit_file.py +64 -55
  20. jarvis/jarvis_tools/file_analyzer.py +17 -28
  21. jarvis/jarvis_tools/read_code.py +80 -81
  22. jarvis/jarvis_utils/builtin_replace_map.py +1 -36
  23. jarvis/jarvis_utils/config.py +13 -48
  24. jarvis/jarvis_utils/embedding.py +6 -51
  25. jarvis/jarvis_utils/git_utils.py +93 -43
  26. jarvis/jarvis_utils/http.py +104 -0
  27. jarvis/jarvis_utils/methodology.py +12 -17
  28. jarvis/jarvis_utils/utils.py +186 -63
  29. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/METADATA +4 -19
  30. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/RECORD +34 -40
  31. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/entry_points.txt +1 -1
  32. jarvis/jarvis_data/huggingface.tar.gz +0 -0
  33. jarvis/jarvis_dev/main.py +0 -1247
  34. jarvis/jarvis_tools/chdir.py +0 -72
  35. jarvis/jarvis_tools/code_plan.py +0 -218
  36. jarvis/jarvis_tools/create_code_agent.py +0 -95
  37. jarvis/jarvis_tools/create_sub_agent.py +0 -82
  38. jarvis/jarvis_tools/file_operation.py +0 -238
  39. jarvis/jarvis_utils/jarvis_history.py +0 -98
  40. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/WHEEL +0 -0
  41. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/licenses/LICENSE +0 -0
  42. {jarvis_ai_assistant-0.1.207.dist-info → jarvis_ai_assistant-0.1.209.dist-info}/top_level.txt +0 -0
@@ -1,72 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- import os
3
- from typing import Any, Dict
4
-
5
-
6
- class ChdirTool:
7
- name = "chdir"
8
- description = "更改当前工作目录"
9
- parameters = {
10
- "type": "object",
11
- "properties": {
12
- "path": {
13
- "type": "string",
14
- "description": "要切换到的目录路径,支持相对路径和绝对路径",
15
- }
16
- },
17
- "required": ["path"],
18
- }
19
-
20
- def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
21
- """执行目录切换操作,并提供全面的错误处理。
22
-
23
- 参数:
24
- args: 包含 'path' 键的字典,目标目录路径
25
-
26
- 返回:
27
- 字典,包含以下内容:
28
- - success: 布尔值,表示操作状态
29
- - stdout: 成功消息或空字符串
30
- - stderr: 错误消息或空字符串
31
-
32
- 异常处理:
33
- 处理并返回适当的错误消息:
34
- - 不存在的路径
35
- - 非目录路径
36
- - 权限错误
37
- - 其他通用异常
38
- """
39
- # 主执行块,包含全面的错误处理
40
- try:
41
- # 规范化并展开输入路径(处理 ~ 和相对路径)
42
- path = os.path.expanduser(args["path"].strip())
43
- path = os.path.abspath(path)
44
-
45
- # 验证目标路径是否存在
46
- if not os.path.exists(path):
47
- return {"success": False, "stdout": "", "stderr": f"目录不存在: {path}"}
48
-
49
- # 确保路径指向的是目录,而不是文件
50
- if not os.path.isdir(path):
51
- return {
52
- "success": False,
53
- "stdout": "",
54
- "stderr": f"路径不是目录: {path}",
55
- }
56
-
57
- # 获取当前目录并尝试切换到新路径
58
- old_path = os.getcwd()
59
- os.chdir(path)
60
-
61
- return {
62
- "success": True,
63
- "stdout": f"成功切换工作目录:\n原目录: {old_path}\n新目录: {path}",
64
- "stderr": "",
65
- }
66
-
67
- # 处理用户没有目录访问权限的情况
68
- except PermissionError:
69
- return {"success": False, "stdout": "", "stderr": f"无权限访问目录: {path}"}
70
- # 捕获在目录切换过程中可能出现的其他意外错误
71
- except Exception as e:
72
- return {"success": False, "stdout": "", "stderr": f"切换目录失败: {str(e)}"}
@@ -1,218 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """代码修改规划工具模块
3
-
4
- 该模块提供CodePlanTool类,用于分析代码修改需求并制定详细的修改计划。
5
- 包含以下主要功能:
6
- 1. 需求理解与分析
7
- 2. 代码修改计划制定
8
- 3. 用户确认流程
9
- 4. 修改计划输出
10
- """
11
-
12
- import os
13
- from typing import Any, Dict
14
-
15
- from jarvis.jarvis_agent import Agent
16
- from jarvis.jarvis_platform.registry import PlatformRegistry
17
- from jarvis.jarvis_tools.registry import ToolRegistry
18
- from jarvis.jarvis_utils.git_utils import find_git_root
19
- from jarvis.jarvis_utils.output import OutputType, PrettyOutput
20
-
21
-
22
- class CodePlanTool:
23
- """用于代码修改规划和需求分析的工具
24
-
25
- 适用场景:
26
- - 理解复杂代码修改需求
27
- - 制定详细的代码修改步骤
28
- - 协调多文件修改计划
29
- - 在修改前获取用户确认
30
-
31
- 工作流程:
32
- 1. 理解需求:通过多种方式(代码查询、用户交互、网络搜索)完全理解需求
33
- 2. 制定计划:分析代码后制定详细的修改步骤
34
- 3. 用户确认:将修改计划呈现给用户确认
35
- 4. 输出计划:按照标准格式输出最终修改计划
36
- """
37
-
38
- name = "code_plan"
39
- description = "理解需求并制定详细的代码修改计划,在修改前获取用户确认"
40
- parameters = {
41
- "type": "object",
42
- "properties": {
43
- "requirement": {"type": "string", "description": "代码修改需求描述"},
44
- "root_dir": {
45
- "type": "string",
46
- "description": "代码库根目录路径(可选)",
47
- "default": ".",
48
- },
49
- },
50
- "required": ["requirement"],
51
- }
52
-
53
- def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
54
- """执行代码规划流程
55
-
56
- Args:
57
- args: 包含:
58
- - requirement: 代码修改需求描述
59
- - root_dir: 代码库根目录路径(可选)
60
-
61
- Returns:
62
- 包含执行结果的字典:
63
- - success: 是否成功
64
- - stdout: 执行结果
65
- - stderr: 错误信息
66
- """
67
- try:
68
- requirement = args["requirement"]
69
- root_dir = args.get("root_dir", ".")
70
-
71
- # 存储当前目录
72
- original_dir = os.getcwd()
73
-
74
- try:
75
- # 切换到root_dir
76
- os.chdir(root_dir)
77
-
78
- # 获取git根目录
79
- git_root: str = find_git_root() or os.getcwd()
80
-
81
- # 创建系统提示
82
- system_prompt = self._create_system_prompt(requirement, git_root)
83
-
84
- # 创建总结提示
85
- summary_prompt = self._create_summary_prompt(requirement)
86
-
87
- # 创建工具注册表
88
- tool_registry: ToolRegistry = ToolRegistry()
89
- tool_registry.use_tools(
90
- ["execute_script", "read_code", "search_web", "ask_user"]
91
- )
92
-
93
- # 创建并运行Agent
94
- platform_registry: PlatformRegistry = PlatformRegistry()
95
- planner_agent = Agent(
96
- system_prompt=system_prompt,
97
- name="CodePlanner",
98
- description="分析代码修改需求并制定详细计划",
99
- summary_prompt=summary_prompt,
100
- platform=platform_registry.get_normal_platform(),
101
- output_handler=[tool_registry],
102
- execute_tool_confirm=False,
103
- auto_complete=False,
104
- )
105
-
106
- # 运行agent并获取结果
107
- task_input = f"分析并规划代码修改: {requirement}"
108
- result = planner_agent.run(task_input)
109
-
110
- return {"success": True, "stdout": result, "stderr": ""}
111
- except (OSError, RuntimeError) as e:
112
- error_msg = f"代码规划失败: {str(e)}"
113
- PrettyOutput.print(error_msg, OutputType.WARNING)
114
- return {"success": False, "stdout": "", "stderr": error_msg}
115
- finally:
116
- # 恢复原始目录
117
- os.chdir(original_dir)
118
- except (KeyError, ValueError) as e:
119
- error_msg = f"代码规划失败: {str(e)}"
120
- PrettyOutput.print(error_msg, OutputType.WARNING)
121
- return {"success": False, "stdout": "", "stderr": error_msg}
122
-
123
- def _create_system_prompt(self, requirement: str, git_root: str) -> str:
124
- """创建Agent的system prompt"""
125
- return f"""# 代码修改规划专家
126
-
127
- ## 任务描述
128
- 分析代码修改需求,理解需求后制定详细的代码修改计划,并在执行前获取用户确认。
129
-
130
- ## 重要原则
131
- - **禁止直接修改代码**:仅提供修改计划,不执行实际代码修改
132
- - **只读分析**:所有代码分析必须基于现有代码,不得假设或虚构代码
133
- - **配置变更优先**:优先考虑通过配置而非代码修改实现需求
134
-
135
- ## 需求信息
136
- - 需求: {requirement}
137
- - 代码库根目录: {git_root}
138
-
139
- ## 工作流程
140
- 1. **需求理解阶段**:
141
- - 使用execute_script工具和read_code工具理解代码
142
- - 必要时使用search_web搜索补充信息
143
- - 使用ask_user工具向用户确认模糊点
144
-
145
- 2. **代码分析阶段**:
146
- - 使用fd/rg查找相关文件
147
- - 使用read_code分析关键文件
148
- - 确定需要修改的文件和范围
149
- - **严格禁止修改代码**:仅分析不修改
150
-
151
- 3. **计划制定阶段**:
152
- - 制定最小变更方案
153
- - 按功能模块分组修改
154
- - 预估修改范围和影响
155
- - **仅输出计划**:不执行实际修改
156
-
157
- 4. **用户确认阶段**:
158
- - 将完整修改计划呈现给用户
159
- - 获取用户明确确认
160
- - 根据反馈调整计划
161
-
162
- 5. **计划输出阶段**:
163
- - 按照summary_prompt格式输出最终计划
164
- - 确保计划清晰、可执行
165
- - **明确标注**:所有修改需用户手动执行
166
-
167
- ## 工具使用优先级
168
- 1. **代码查询工具**:
169
- - fd/rg: 查找文件和代码模式
170
- - read_code: 读取文件内容
171
-
172
- 2. **信息补充工具**:
173
- - search_web: 搜索技术实现方案
174
- - ask_user: 确认需求细节
175
-
176
- ## 计划制定原则
177
- - **只读原则**:所有分析必须基于现有代码,不得修改
178
- - 最小变更原则: 保持现有代码结构
179
- - 模块化修改: 按功能分组修改
180
- - 影响分析: 评估修改的影响范围
181
- - 风格一致: 保持代码风格统一"""
182
-
183
- def _create_summary_prompt(self, requirement: str) -> str:
184
- """创建Agent的summary prompt"""
185
- return f"""# 代码修改计划报告
186
-
187
- ## 报告要求
188
- 生成关于以下需求的清晰、可执行的代码修改计划:
189
-
190
- **需求**: {requirement}
191
-
192
- 报告应包含:
193
-
194
- 1. **需求分析**:
195
- - 需求的完整理解
196
- - 关键功能点和边界条件
197
- - 任何假设和前提条件
198
-
199
- 2. **代码现状**:
200
- - 相关文件和模块
201
- - 现有实现分析
202
- - 需要修改的部分
203
-
204
- 3. **修改计划**:
205
- - 需要修改的文件列表
206
- - 每个文件的修改内容概述
207
- - 修改步骤和顺序
208
- - 预估影响范围
209
-
210
- 4. **验证方案**:
211
- - 如何验证修改的正确性
212
- - 需要添加的测试用例
213
-
214
- 5. **用户确认**:
215
- - 明确标记已获得用户确认
216
- - 记录用户的任何特殊要求
217
-
218
- 使用清晰的Markdown格式,重点突出修改计划和验证方案。"""
@@ -1,95 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- import os
3
- from typing import Any, Dict
4
-
5
- from jarvis.jarvis_code_agent.code_agent import CodeAgent
6
- from jarvis.jarvis_git_utils.git_commiter import GitCommitTool
7
- from jarvis.jarvis_utils.git_utils import (get_latest_commit_hash,
8
- has_uncommitted_changes)
9
- from jarvis.jarvis_utils.output import OutputType, PrettyOutput
10
-
11
-
12
- class CreateCodeAgentTool:
13
- """用于管理代码开发工作流的工具"""
14
-
15
- name = "create_code_agent"
16
- description = "代码开发工具,当需要修改代码时使用,如果只是简单文件修改,使用文件操作或者脚本即可"
17
- parameters = {
18
- "requirement": """代码实现的技术规范,必须包含以下完整信息:
19
- 1. 项目代码目录 - 项目根目录的绝对路径
20
- 2. 项目功能 - 项目的主要功能和目标
21
- 3. 本次要实现的feature - 本次开发要完成的具体功能需求
22
- 4. 涉及的文件 - 需要修改或新增的文件列表
23
- 5. 额外需要注意的信息 - 开发时需要额外注意的信息
24
- """,
25
- "root_dir": {
26
- "type": "string",
27
- "description": "代码库根目录路径(可选)",
28
- "default": ".",
29
- },
30
- }
31
-
32
- def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
33
- try:
34
- requirement = args.get("requirement", "")
35
- root_dir = args.get("root_dir", ".")
36
-
37
- # Store current directory
38
- original_dir = os.getcwd()
39
-
40
- try:
41
- # Change to root_dir
42
- os.chdir(root_dir)
43
- if not requirement:
44
- return {
45
- "success": False,
46
- "stderr": "Requirement must be provided",
47
- "stdout": "",
48
- }
49
-
50
- # Step 1: Handle uncommitted changes
51
- start_commit = None
52
- if has_uncommitted_changes():
53
- PrettyOutput.print("发现未提交的更改,正在提交...", OutputType.INFO)
54
- git_commiter = GitCommitTool()
55
- result = git_commiter.execute({})
56
- if not result["success"]:
57
- return {
58
- "success": False,
59
- "stderr": "Failed to commit changes: " + result["stderr"],
60
- "stdout": "",
61
- }
62
-
63
- # Get current commit hash
64
- start_commit = get_latest_commit_hash()
65
-
66
- # Step 2: Development
67
- PrettyOutput.print("开始开发...", OutputType.INFO)
68
- agent = CodeAgent()
69
- agent.run(requirement)
70
-
71
- # Get new commit hash after development
72
- end_commit = get_latest_commit_hash()
73
-
74
- # Step 4: Generate Summary
75
- summary = f"""开发总结:
76
-
77
- 开始提交: {start_commit}
78
- 结束提交: {end_commit}
79
-
80
- 需求:
81
- {requirement}
82
-
83
- """
84
-
85
- return {"success": True, "stdout": summary, "stderr": ""}
86
- finally:
87
- # Always restore original directory
88
- os.chdir(original_dir)
89
-
90
- except Exception as e:
91
- return {
92
- "success": False,
93
- "stderr": f"Development workflow failed: {str(e)}",
94
- "stdout": "",
95
- }
@@ -1,82 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- import os
3
- from typing import Any, Dict
4
-
5
- from jarvis.jarvis_agent import Agent, origin_agent_system_prompt
6
- from jarvis.jarvis_utils.output import OutputType, PrettyOutput
7
-
8
-
9
- class SubAgentTool:
10
- name = "create_sub_agent"
11
- description = "创建子代理以处理特定任务,子代理将生成任务总结报告"
12
- parameters = {
13
- "type": "object",
14
- "properties": {
15
- "agent_name": {"type": "string", "description": "子代理名称"},
16
- "task": {"type": "string", "description": "要完成的特定任务"},
17
- "context": {
18
- "type": "string",
19
- "description": "与任务相关的上下文信息",
20
- "default": "",
21
- },
22
- "goal": {"type": "string", "description": "任务的完成目标", "default": ""},
23
- "root_dir": {
24
- "type": "string",
25
- "description": "任务执行的根目录路径(可选)",
26
- "default": ".",
27
- },
28
- },
29
- "required": ["agent_name", "task"],
30
- }
31
-
32
- def execute(self, args: Dict) -> Dict[str, Any]:
33
- """Create and run sub-agent"""
34
- try:
35
- agent_name = args["agent_name"]
36
- task = args["task"]
37
- context = args.get("context", "")
38
- goal = args.get("goal", "")
39
- root_dir = args.get("root_dir", ".")
40
-
41
- PrettyOutput.print(f"创建子代理: {agent_name}", OutputType.INFO)
42
-
43
- # Build task description
44
- task_description = task
45
- if context:
46
- task_description = f"Context information:\n{context}\n\nTask:\n{task}"
47
- if goal:
48
- task_description += f"\n\nCompletion goal:\n{goal}"
49
-
50
- # Store current directory
51
- original_dir = os.getcwd()
52
-
53
- try:
54
- # Change to root_dir
55
- os.chdir(root_dir)
56
-
57
- # Create sub-agent
58
- sub_agent = Agent(
59
- system_prompt=origin_agent_system_prompt,
60
- name=f"Agent({agent_name})",
61
- )
62
-
63
- # Run sub-agent, pass file list
64
- PrettyOutput.print("子代理开始执行任务...", OutputType.INFO)
65
- result = sub_agent.run(task_description)
66
-
67
- return {
68
- "success": True,
69
- "stdout": f"Sub-agent task completed\n\n{result}",
70
- "stderr": "",
71
- }
72
- finally:
73
- # Always restore original directory
74
- os.chdir(original_dir)
75
-
76
- except Exception as e:
77
- PrettyOutput.print(str(e), OutputType.ERROR)
78
- return {
79
- "success": False,
80
- "stdout": "",
81
- "stderr": f"Sub-agent execution failed: {str(e)}",
82
- }