jarvis-ai-assistant 0.1.189__py3-none-any.whl → 0.1.190__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.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_git_utils/git_commiter.py +1 -0
- jarvis/jarvis_tools/generate_new_tool.py +88 -40
- jarvis/jarvis_tools/registry.py +2 -0
- {jarvis_ai_assistant-0.1.189.dist-info → jarvis_ai_assistant-0.1.190.dist-info}/METADATA +13 -2
- {jarvis_ai_assistant-0.1.189.dist-info → jarvis_ai_assistant-0.1.190.dist-info}/RECORD +10 -10
- {jarvis_ai_assistant-0.1.189.dist-info → jarvis_ai_assistant-0.1.190.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.189.dist-info → jarvis_ai_assistant-0.1.190.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.189.dist-info → jarvis_ai_assistant-0.1.190.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.189.dist-info → jarvis_ai_assistant-0.1.190.dist-info}/top_level.txt +0 -0
jarvis/__init__.py
CHANGED
@@ -77,6 +77,7 @@ class GitCommitTool:
|
|
77
77
|
def execute(self, args: Dict) -> Dict[str, Any]:
|
78
78
|
"""Execute automatic commit process with support for multi-line messages and special characters"""
|
79
79
|
try:
|
80
|
+
original_dir = os.getcwd()
|
80
81
|
root_dir = args.get("root_dir", ".")
|
81
82
|
prefix = args.get("prefix", "")
|
82
83
|
suffix = args.get("suffix", "")
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
import re
|
3
2
|
from pathlib import Path
|
4
|
-
from typing import Any, Dict
|
3
|
+
from typing import Any, Dict
|
5
4
|
|
6
5
|
from jarvis.jarvis_utils.config import get_data_dir
|
7
6
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
@@ -14,20 +13,20 @@ class generate_new_tool:
|
|
14
13
|
并自动注册到当前的工具注册表中。适用场景:1. 需要创建新的自定义工具;
|
15
14
|
2. 扩展Jarvis功能;3. 自动化重复性操作;4. 封装特定领域的功能。
|
16
15
|
"""
|
17
|
-
|
16
|
+
|
18
17
|
parameters = {
|
19
18
|
"type": "object",
|
20
19
|
"properties": {
|
21
20
|
"tool_name": {
|
22
21
|
"type": "string",
|
23
|
-
"description": "新工具的名称,将用作文件名和工具类名"
|
22
|
+
"description": "新工具的名称,将用作文件名和工具类名",
|
24
23
|
},
|
25
24
|
"tool_code": {
|
26
25
|
"type": "string",
|
27
|
-
"description": "工具的完整Python代码,包含类定义、名称、描述、参数和execute方法"
|
28
|
-
}
|
26
|
+
"description": "工具的完整Python代码,包含类定义、名称、描述、参数和execute方法",
|
27
|
+
},
|
29
28
|
},
|
30
|
-
"required": ["tool_name", "tool_code"]
|
29
|
+
"required": ["tool_name", "tool_code"],
|
31
30
|
}
|
32
31
|
|
33
32
|
@staticmethod
|
@@ -36,16 +35,18 @@ class generate_new_tool:
|
|
36
35
|
# 检查数据目录是否存在
|
37
36
|
data_dir = get_data_dir()
|
38
37
|
tools_dir = Path(data_dir) / "tools"
|
39
|
-
|
38
|
+
|
40
39
|
# 如果tools目录不存在,尝试创建
|
41
40
|
if not tools_dir.exists():
|
42
41
|
try:
|
43
42
|
tools_dir.mkdir(parents=True, exist_ok=True)
|
44
43
|
return True
|
45
44
|
except Exception as e:
|
46
|
-
PrettyOutput.print(
|
45
|
+
PrettyOutput.print(
|
46
|
+
f"无法创建工具目录 {tools_dir}: {e}", OutputType.ERROR
|
47
|
+
)
|
47
48
|
return False
|
48
|
-
|
49
|
+
|
49
50
|
return True
|
50
51
|
|
51
52
|
def execute(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
@@ -64,83 +65,130 @@ class generate_new_tool:
|
|
64
65
|
tool_name = args["tool_name"]
|
65
66
|
tool_code = args["tool_code"]
|
66
67
|
agent = args.get("agent", None)
|
67
|
-
|
68
|
+
|
68
69
|
# 验证工具名称
|
69
70
|
if not tool_name.isidentifier():
|
70
71
|
return {
|
71
72
|
"success": False,
|
72
73
|
"stdout": "",
|
73
|
-
"stderr": f"工具名称 '{tool_name}' 不是有效的Python标识符"
|
74
|
+
"stderr": f"工具名称 '{tool_name}' 不是有效的Python标识符",
|
74
75
|
}
|
75
|
-
|
76
|
+
|
76
77
|
# 准备工具目录
|
77
78
|
tools_dir = Path(get_data_dir()) / "tools"
|
78
79
|
tools_dir.mkdir(parents=True, exist_ok=True)
|
79
|
-
|
80
|
+
|
80
81
|
# 生成工具文件路径
|
81
82
|
tool_file_path = tools_dir / f"{tool_name}.py"
|
82
|
-
|
83
|
+
|
83
84
|
# 检查是否已存在同名工具
|
84
85
|
if tool_file_path.exists():
|
85
86
|
return {
|
86
87
|
"success": False,
|
87
88
|
"stdout": "",
|
88
|
-
"stderr": f"工具 '{tool_name}' 已经存在于 {tool_file_path}"
|
89
|
+
"stderr": f"工具 '{tool_name}' 已经存在于 {tool_file_path}",
|
89
90
|
}
|
90
|
-
|
91
|
+
|
91
92
|
# 写入工具文件
|
92
93
|
with open(tool_file_path, "w", encoding="utf-8") as f:
|
93
94
|
f.write(tool_code)
|
94
|
-
|
95
|
+
|
95
96
|
# 注册新工具到当前的工具注册表
|
96
97
|
success_message = f"工具 '{tool_name}' 已成功生成在 {tool_file_path}"
|
97
|
-
|
98
|
+
|
98
99
|
registration_successful = False
|
99
100
|
if agent:
|
100
101
|
tool_registry = agent.get_tool_registry()
|
101
102
|
if tool_registry:
|
102
103
|
# 尝试加载并注册新工具
|
103
|
-
PrettyOutput.print(
|
104
|
+
PrettyOutput.print(
|
105
|
+
f"正在注册工具 '{tool_name}'...", OutputType.INFO
|
106
|
+
)
|
104
107
|
if tool_registry.register_tool_by_file(str(tool_file_path)):
|
105
108
|
success_message += f"\n已成功注册到当前会话的工具注册表中"
|
106
109
|
registration_successful = True
|
107
110
|
else:
|
108
111
|
# 注册失败,删除已创建的文件
|
109
|
-
PrettyOutput.print(
|
112
|
+
PrettyOutput.print(
|
113
|
+
f"注册工具 '{tool_name}' 失败,正在删除文件...",
|
114
|
+
OutputType.WARNING,
|
115
|
+
)
|
110
116
|
if tool_file_path.exists():
|
111
117
|
tool_file_path.unlink()
|
112
118
|
return {
|
113
119
|
"success": False,
|
114
120
|
"stdout": "",
|
115
|
-
"stderr": f"工具文件已生成,但注册失败。文件已被删除。"
|
121
|
+
"stderr": f"工具文件已生成,但注册失败。文件已被删除。",
|
116
122
|
}
|
117
123
|
else:
|
118
|
-
PrettyOutput.print(
|
124
|
+
PrettyOutput.print(
|
125
|
+
"未找到工具注册表,无法自动注册工具", OutputType.WARNING
|
126
|
+
)
|
119
127
|
success_message += f"\n注册到当前会话失败,可能需要重新启动Jarvis"
|
120
|
-
|
121
|
-
PrettyOutput.print(
|
122
|
-
|
123
|
-
"
|
124
|
-
"
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
+
|
129
|
+
PrettyOutput.print(
|
130
|
+
f"工具 '{tool_name}' 创建"
|
131
|
+
+ ("并注册" if registration_successful else "")
|
132
|
+
+ "成功!",
|
133
|
+
OutputType.SUCCESS,
|
134
|
+
)
|
135
|
+
|
136
|
+
# 检查并安装缺失的依赖
|
137
|
+
try:
|
138
|
+
import re
|
139
|
+
|
140
|
+
required_packages = set()
|
141
|
+
|
142
|
+
# 从代码中提取import语句
|
143
|
+
for line in tool_code.split("\n"):
|
144
|
+
if line.strip().startswith("import "):
|
145
|
+
# 处理 import a.b.c 形式
|
146
|
+
pkg = line.split()[1].split(".")[0]
|
147
|
+
required_packages.add(pkg)
|
148
|
+
elif line.strip().startswith("from "):
|
149
|
+
# 处理 from a.b.c import d 形式
|
150
|
+
parts = line.split()
|
151
|
+
if (
|
152
|
+
len(parts) >= 4
|
153
|
+
and parts[0] == "from"
|
154
|
+
and parts[2] == "import"
|
155
|
+
):
|
156
|
+
pkg = parts[1].split(".")[0]
|
157
|
+
required_packages.add(pkg)
|
158
|
+
|
159
|
+
# 检查并安装缺失的包
|
160
|
+
for pkg in required_packages:
|
161
|
+
try:
|
162
|
+
__import__(pkg)
|
163
|
+
except ImportError:
|
164
|
+
PrettyOutput.print(
|
165
|
+
f"检测到缺失依赖: {pkg}, 正在尝试安装...", OutputType.INFO
|
166
|
+
)
|
167
|
+
import subprocess
|
168
|
+
|
169
|
+
subprocess.run(["pip", "install", pkg], check=True)
|
170
|
+
PrettyOutput.print(f"成功安装依赖: {pkg}", OutputType.SUCCESS)
|
171
|
+
except Exception as e:
|
172
|
+
PrettyOutput.print(f"依赖检查/安装失败: {str(e)}", OutputType.WARNING)
|
173
|
+
|
174
|
+
return {"success": True, "stdout": success_message, "stderr": ""}
|
175
|
+
|
128
176
|
except Exception as e:
|
129
177
|
# 如果发生异常,删除已创建的文件并返回失败响应
|
130
178
|
error_msg = f"生成工具失败: {str(e)}"
|
131
179
|
PrettyOutput.print(error_msg, OutputType.ERROR)
|
132
|
-
|
180
|
+
|
133
181
|
# 删除已创建的文件
|
134
182
|
if tool_file_path and tool_file_path.exists():
|
135
183
|
try:
|
136
|
-
PrettyOutput.print(
|
184
|
+
PrettyOutput.print(
|
185
|
+
f"正在删除已创建的文件 {tool_file_path}...", OutputType.INFO
|
186
|
+
)
|
137
187
|
tool_file_path.unlink()
|
138
188
|
PrettyOutput.print(f"文件已删除", OutputType.SUCCESS)
|
139
189
|
except Exception as delete_error:
|
140
|
-
PrettyOutput.print(
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
"stderr": error_msg
|
146
|
-
}
|
190
|
+
PrettyOutput.print(
|
191
|
+
f"删除文件失败: {str(delete_error)}", OutputType.ERROR
|
192
|
+
)
|
193
|
+
|
194
|
+
return {"success": False, "stdout": "", "stderr": error_msg}
|
jarvis/jarvis_tools/registry.py
CHANGED
@@ -685,6 +685,8 @@ class ToolRegistry(OutputHandlerProtocol):
|
|
685
685
|
agent_instance.clear_history()
|
686
686
|
upload_success = agent_instance.model.upload_files([output_file])
|
687
687
|
if upload_success:
|
688
|
+
# 删除args的agent键
|
689
|
+
args.pop("agent", None)
|
688
690
|
prompt = f"""
|
689
691
|
以下是之前对话的关键信息总结:
|
690
692
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: jarvis-ai-assistant
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.190
|
4
4
|
Summary: Jarvis: An AI assistant that uses tools to interact with the system
|
5
5
|
Home-page: https://github.com/skyfireitdiy/Jarvis
|
6
6
|
Author: skyfire
|
@@ -113,6 +113,18 @@ pip3 install -e .
|
|
113
113
|
pip3 install jarvis-ai-assistant
|
114
114
|
```
|
115
115
|
|
116
|
+
### 预定义任务(pre-command)
|
117
|
+
|
118
|
+
您可以创建预定义任务文件来快速执行常用命令:
|
119
|
+
|
120
|
+
1. 在`~/.jarvis/pre-command`或当前目录的`.jarvis/pre-command`文件中定义任务
|
121
|
+
2. 使用YAML格式定义任务,例如:
|
122
|
+
```yaml
|
123
|
+
build: "构建项目并运行测试"
|
124
|
+
deploy: "部署应用到生产环境"
|
125
|
+
```
|
126
|
+
3. 运行`jarvis`命令时会自动加载这些任务并提示选择执行
|
127
|
+
|
116
128
|
### 最小化配置
|
117
129
|
|
118
130
|
将以下配置写入到`~/.jarvis/config.yaml`文件中。
|
@@ -215,7 +227,6 @@ OPENAI_API_BASE: https://api.openai.com/v1 # 可选,默认为官方API地址
|
|
215
227
|
| `jarvis-multi-agent` | - | 使用多代理功能 |
|
216
228
|
| `jarvis-agent` | - | 使用agent功能 |
|
217
229
|
| `jarvis-tool` | - | 使用工具功能 |
|
218
|
-
| `jarvis-ask-codebase` | `jac` | 使用代码库查询功能 |
|
219
230
|
| `jarvis-git-details` | - | 使用git details功能 |
|
220
231
|
| `jarvis-methodology` | - | 使用方法论功能 |
|
221
232
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
jarvis/__init__.py,sha256=
|
1
|
+
jarvis/__init__.py,sha256=4h6TNgKLF0A6znYlkXoPrVCeP9Pj6DTrNF6NbH9Oroo,74
|
2
2
|
jarvis/jarvis_agent/__init__.py,sha256=utqI92rkiqiVR2zk5N-IQe2CeMSl-sNiLU429dLoGVw,30487
|
3
3
|
jarvis/jarvis_agent/builtin_input_handler.py,sha256=f4DaEHPakXcAbgykFP-tiOQP6fh_yGFlZx_h91_j2tQ,1529
|
4
4
|
jarvis/jarvis_agent/file_input_handler.py,sha256=OfoYI5on6w5BDUUg4OadFcfWzMsUF70GNrlt9QyauvA,4181
|
@@ -38,7 +38,7 @@ jarvis/jarvis_git_details/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
38
38
|
jarvis/jarvis_git_details/main.py,sha256=4L60eVDBMv6RbocnVlzfOx7JZkHTzop3q7qui9d9LuU,9005
|
39
39
|
jarvis/jarvis_git_squash/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
40
40
|
jarvis/jarvis_git_squash/main.py,sha256=q8-r0TtVOaCqY_uYwnWAY76k8YCDd5se_feB6ZWKo9M,2278
|
41
|
-
jarvis/jarvis_git_utils/git_commiter.py,sha256=
|
41
|
+
jarvis/jarvis_git_utils/git_commiter.py,sha256=CPIBfTJw10VRZRxREqnSnUhooOVGwobUCOzEjZ1kWas,13076
|
42
42
|
jarvis/jarvis_mcp/__init__.py,sha256=NF_vqRxaNyz8ColcpRh0bOkinV90YLAKHEN--jkP-B8,2114
|
43
43
|
jarvis/jarvis_mcp/sse_mcp_client.py,sha256=QNA7HqFvLbvhNaFp3ZsXzs2Rm6_gHUMcpd4t4qAzymY,23485
|
44
44
|
jarvis/jarvis_mcp/stdio_mcp_client.py,sha256=IEkas4ojP5J0TdVaUglvlEp61RyezBtuejv4lN3n1I4,11831
|
@@ -69,11 +69,11 @@ jarvis/jarvis_tools/edit_file.py,sha256=s8HqG8qHDrYjCwIioeBpGvw7Aw-iEEZoUyRJFqdj
|
|
69
69
|
jarvis/jarvis_tools/execute_script.py,sha256=IA1SkcnwBB9PKG2voBNx5N9GXL303OC7OOtdqRfqWOk,6428
|
70
70
|
jarvis/jarvis_tools/file_analyzer.py,sha256=UuQmti-eBocJB6ivMINmOvSuXxBxOqmbQ3RsQlyueWs,4918
|
71
71
|
jarvis/jarvis_tools/file_operation.py,sha256=WloC1-oPJLwgICu4WBc9f7XA8N_Ggl73QQ5CxM2XTlE,9464
|
72
|
-
jarvis/jarvis_tools/generate_new_tool.py,sha256=
|
72
|
+
jarvis/jarvis_tools/generate_new_tool.py,sha256=KZX4wpSpBZ4S5817zAN5j7AAirtgBCrNUmjrpfL9dNI,7706
|
73
73
|
jarvis/jarvis_tools/methodology.py,sha256=m7cQmVhhQpUUl_uYTVvcW0JBovQLx5pWTXh_8K77HsU,5237
|
74
74
|
jarvis/jarvis_tools/read_code.py,sha256=pL2SwZDsJbJMXo4stW96quFsLgbtPVIAW-h4sDKsLtM,6274
|
75
75
|
jarvis/jarvis_tools/read_webpage.py,sha256=PFAYuKjay9j6phWzyuZ99ZfNaHJljmRWAgS0bsvbcvE,2219
|
76
|
-
jarvis/jarvis_tools/registry.py,sha256=
|
76
|
+
jarvis/jarvis_tools/registry.py,sha256=339NBh4qZHsiBKMHgKV2kgDVhEkeZqiSJnZTedGMK8o,25162
|
77
77
|
jarvis/jarvis_tools/rewrite_file.py,sha256=3V2l7kG5DG9iRimBce-1qCRuJPL0QM32SBTzOl2zCqM,7004
|
78
78
|
jarvis/jarvis_tools/search_web.py,sha256=rzxrCOTEo-MmLQrKI4k-AbfidUfJUeCPK4f5ZJy48G8,952
|
79
79
|
jarvis/jarvis_tools/virtual_tty.py,sha256=8E_n-eC-RRPTqYx6BI5Q2RnorY8dbhKFBfAjIiRQROA,16397
|
@@ -91,9 +91,9 @@ jarvis/jarvis_utils/methodology.py,sha256=6vf__ahwJZ2I62mWGAvh2C-G6pq930Dh_EkrY1
|
|
91
91
|
jarvis/jarvis_utils/output.py,sha256=QboL42GtG_dnvd1O64sl8o72mEBhXNRADPXQMXgDE7Q,9661
|
92
92
|
jarvis/jarvis_utils/tag.py,sha256=YJHmuedLb7_AiqvKQetHr4R1FxyzIh7HN0RRkWMmYbU,429
|
93
93
|
jarvis/jarvis_utils/utils.py,sha256=dTFIN6EV48BuC4VOyvcVcj4P0tsWysc9ennbMRhLJjk,10960
|
94
|
-
jarvis_ai_assistant-0.1.
|
95
|
-
jarvis_ai_assistant-0.1.
|
96
|
-
jarvis_ai_assistant-0.1.
|
97
|
-
jarvis_ai_assistant-0.1.
|
98
|
-
jarvis_ai_assistant-0.1.
|
99
|
-
jarvis_ai_assistant-0.1.
|
94
|
+
jarvis_ai_assistant-0.1.190.dist-info/licenses/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
|
95
|
+
jarvis_ai_assistant-0.1.190.dist-info/METADATA,sha256=3Dz7yIwWszneilEi9OfdiqzumWW0ruMLLjbzqZKC7RA,16257
|
96
|
+
jarvis_ai_assistant-0.1.190.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
97
|
+
jarvis_ai_assistant-0.1.190.dist-info/entry_points.txt,sha256=Gy3DOP1PYLMK0GCj4rrP_9lkOyBQ39EK_lKGUSwn41E,869
|
98
|
+
jarvis_ai_assistant-0.1.190.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
|
99
|
+
jarvis_ai_assistant-0.1.190.dist-info/RECORD,,
|
File without changes
|
{jarvis_ai_assistant-0.1.189.dist-info → jarvis_ai_assistant-0.1.190.dist-info}/entry_points.txt
RENAMED
File without changes
|
{jarvis_ai_assistant-0.1.189.dist-info → jarvis_ai_assistant-0.1.190.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
{jarvis_ai_assistant-0.1.189.dist-info → jarvis_ai_assistant-0.1.190.dist-info}/top_level.txt
RENAMED
File without changes
|