jarvis-ai-assistant 0.1.128__py3-none-any.whl → 0.1.130__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 +26 -31
- jarvis/jarvis_agent/main.py +77 -0
- jarvis/jarvis_c2rust/c2rust.yaml +734 -0
- jarvis/jarvis_code_agent/builtin_input_handler.py +43 -0
- jarvis/jarvis_code_agent/code_agent.py +82 -156
- jarvis/jarvis_code_agent/file_input_handler.py +88 -0
- jarvis/jarvis_code_agent/patch.py +262 -80
- jarvis/jarvis_code_agent/shell_input_handler.py +8 -2
- jarvis/jarvis_dev/main.py +832 -740
- jarvis/jarvis_multi_agent/__init__.py +113 -92
- jarvis/jarvis_platform/registry.py +0 -1
- jarvis/jarvis_tools/create_sub_agent.py +1 -8
- jarvis/jarvis_tools/git_commiter.py +2 -1
- jarvis/jarvis_tools/read_code.py +143 -0
- jarvis/jarvis_tools/registry.py +35 -39
- jarvis/jarvis_tools/tool_generator.py +45 -17
- jarvis/jarvis_utils/__init__.py +17 -17
- jarvis/jarvis_utils/config.py +87 -51
- jarvis/jarvis_utils/embedding.py +49 -48
- jarvis/jarvis_utils/git_utils.py +34 -34
- jarvis/jarvis_utils/globals.py +26 -26
- jarvis/jarvis_utils/input.py +61 -45
- jarvis/jarvis_utils/methodology.py +22 -22
- jarvis/jarvis_utils/output.py +64 -64
- jarvis/jarvis_utils/utils.py +2 -2
- {jarvis_ai_assistant-0.1.128.dist-info → jarvis_ai_assistant-0.1.130.dist-info}/METADATA +1 -1
- {jarvis_ai_assistant-0.1.128.dist-info → jarvis_ai_assistant-0.1.130.dist-info}/RECORD +32 -27
- {jarvis_ai_assistant-0.1.128.dist-info → jarvis_ai_assistant-0.1.130.dist-info}/entry_points.txt +2 -0
- {jarvis_ai_assistant-0.1.128.dist-info → jarvis_ai_assistant-0.1.130.dist-info}/LICENSE +0 -0
- {jarvis_ai_assistant-0.1.128.dist-info → jarvis_ai_assistant-0.1.130.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.128.dist-info → jarvis_ai_assistant-0.1.130.dist-info}/top_level.txt +0 -0
|
@@ -7,13 +7,12 @@ from yaspin import yaspin
|
|
|
7
7
|
from jarvis.jarvis_agent.output_handler import OutputHandler
|
|
8
8
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
9
9
|
from jarvis.jarvis_tools.git_commiter import GitCommitTool
|
|
10
|
-
from jarvis.jarvis_tools.execute_shell_script import ShellScriptTool
|
|
11
10
|
from jarvis.jarvis_tools.file_operation import FileOperationTool
|
|
12
11
|
from jarvis.jarvis_utils.config import is_confirm_before_apply_patch
|
|
13
12
|
from jarvis.jarvis_utils.git_utils import get_commits_between, get_latest_commit_hash
|
|
14
13
|
from jarvis.jarvis_utils.input import get_multiline_input
|
|
15
14
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
16
|
-
from jarvis.jarvis_utils.utils import user_confirm
|
|
15
|
+
from jarvis.jarvis_utils.utils import get_file_line_count, user_confirm
|
|
17
16
|
|
|
18
17
|
class PatchOutputHandler(OutputHandler):
|
|
19
18
|
def name(self) -> str:
|
|
@@ -28,25 +27,47 @@ class PatchOutputHandler(OutputHandler):
|
|
|
28
27
|
|
|
29
28
|
def prompt(self) -> str:
|
|
30
29
|
return """
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
# 代码补丁规范
|
|
31
|
+
|
|
32
|
+
## 补丁格式定义
|
|
33
|
+
使用<PATCH>块来精确指定代码更改:
|
|
34
|
+
```
|
|
34
35
|
<PATCH>
|
|
35
36
|
File: [文件路径]
|
|
36
37
|
Reason: [修改原因]
|
|
37
38
|
[上下文代码片段]
|
|
38
39
|
</PATCH>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 核心原则
|
|
43
|
+
1. **上下文完整性**:代码片段必须包含足够的上下文(修改前后各3行)
|
|
44
|
+
2. **精准修改**:只显示需要修改的代码部分,不需要展示整个文件内容
|
|
45
|
+
3. **格式严格保持**:
|
|
46
|
+
- 严格保持原始代码的缩进方式(空格或制表符)
|
|
47
|
+
- 保持原始代码的空行数量和位置
|
|
48
|
+
- 保持原始代码的行尾空格处理方式
|
|
49
|
+
- 不改变原始代码的换行风格
|
|
50
|
+
4. **新旧区分**:
|
|
51
|
+
- 对于新文件:提供完整的代码内容
|
|
52
|
+
- 对于现有文件:保留周围未更改的代码,突出显示变更部分
|
|
53
|
+
5. **理由说明**:每个补丁必须包含清晰的修改理由,解释为什么需要此更改
|
|
54
|
+
|
|
55
|
+
## 格式兼容性要求
|
|
56
|
+
1. **缩进一致性**:
|
|
57
|
+
- 如果原代码使用4个空格缩进,补丁也必须使用4个空格缩进
|
|
58
|
+
- 如果原代码使用制表符缩进,补丁也必须使用制表符缩进
|
|
59
|
+
2. **空行保留**:
|
|
60
|
+
- 如果原代码在函数之间有两个空行,补丁也必须保留这两个空行
|
|
61
|
+
- 如果原代码在类方法之间有一个空行,补丁也必须保留这一个空行
|
|
62
|
+
3. **行尾处理**:
|
|
63
|
+
- 如果原代码行尾没有空格,补丁也不应添加行尾空格
|
|
64
|
+
- 如果原代码使用特定的行尾注释风格,补丁也应保持该风格
|
|
65
|
+
|
|
66
|
+
## 补丁示例
|
|
67
|
+
```
|
|
47
68
|
<PATCH>
|
|
48
69
|
File: src/utils/math.py
|
|
49
|
-
Reason:
|
|
70
|
+
Reason: 修复除零错误,增加参数验证以提高函数健壮性
|
|
50
71
|
def safe_divide(a, b):
|
|
51
72
|
# 添加参数验证
|
|
52
73
|
if b == 0:
|
|
@@ -56,6 +77,14 @@ def safe_divide(a, b):
|
|
|
56
77
|
def add(a, b):
|
|
57
78
|
return a + b
|
|
58
79
|
</PATCH>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 最佳实践
|
|
83
|
+
- 每个补丁专注于单一职责的修改
|
|
84
|
+
- 提供足够的上下文,但避免包含过多无关代码
|
|
85
|
+
- 确保修改理由清晰明确,便于理解变更目的
|
|
86
|
+
- 保持代码风格一致性,遵循项目现有的编码规范
|
|
87
|
+
- 在修改前仔细分析原代码的格式风格,确保补丁与之完全兼容
|
|
59
88
|
"""
|
|
60
89
|
|
|
61
90
|
def _parse_patch(patch_str: str) -> Dict[str, str]:
|
|
@@ -91,8 +120,22 @@ def apply_patch(output_str: str) -> str:
|
|
|
91
120
|
for filepath, patch_content in patches.items():
|
|
92
121
|
try:
|
|
93
122
|
spinner.text = f"正在处理文件: {filepath}"
|
|
123
|
+
if not os.path.exists(filepath):
|
|
124
|
+
# 新建文件
|
|
125
|
+
spinner.text = "文件不存在,正在创建文件..."
|
|
126
|
+
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
|
127
|
+
open(filepath, 'w', encoding='utf-8').close()
|
|
128
|
+
spinner.write("✅ 文件创建完成")
|
|
94
129
|
with spinner.hidden():
|
|
95
|
-
|
|
130
|
+
retry_count = 3
|
|
131
|
+
while not handle_code_operation(filepath, patch_content):
|
|
132
|
+
retry_count -= 1
|
|
133
|
+
if retry_count > 0:
|
|
134
|
+
continue
|
|
135
|
+
if user_confirm("补丁应用失败,是否重试?", default=True):
|
|
136
|
+
pass
|
|
137
|
+
else:
|
|
138
|
+
raise Exception("补丁应用失败")
|
|
96
139
|
spinner.write(f"✅ 文件 {filepath} 处理完成")
|
|
97
140
|
except Exception as e:
|
|
98
141
|
spinner.text = f"文件 {filepath} 处理失败: {str(e)}, 回滚文件"
|
|
@@ -122,16 +165,18 @@ def apply_patch(output_str: str) -> str:
|
|
|
122
165
|
else:
|
|
123
166
|
final_ret += "✅ 补丁已应用(没有新的提交)"
|
|
124
167
|
else:
|
|
125
|
-
final_ret += "❌
|
|
168
|
+
final_ret += "❌ 我拒绝应用此补丁\n"
|
|
126
169
|
final_ret += "补丁预览:\n"
|
|
127
170
|
final_ret += diff
|
|
128
171
|
else:
|
|
129
172
|
final_ret += "❌ 没有要提交的更改\n"
|
|
130
173
|
# 用户确认最终结果
|
|
131
174
|
PrettyOutput.print(final_ret, OutputType.USER)
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
175
|
+
with spinner.hidden():
|
|
176
|
+
if not is_confirm_before_apply_patch() or user_confirm("是否使用此回复?", default=True):
|
|
177
|
+
return final_ret
|
|
178
|
+
return get_multiline_input("请输入自定义回复")
|
|
179
|
+
|
|
135
180
|
def revert_file(filepath: str):
|
|
136
181
|
"""增强版git恢复,处理新文件"""
|
|
137
182
|
import subprocess
|
|
@@ -171,6 +216,7 @@ def get_diff() -> str:
|
|
|
171
216
|
return ret
|
|
172
217
|
except subprocess.CalledProcessError as e:
|
|
173
218
|
return f"获取差异失败: {str(e)}"
|
|
219
|
+
|
|
174
220
|
def handle_commit_workflow()->bool:
|
|
175
221
|
"""Handle the git commit workflow and return the commit details.
|
|
176
222
|
|
|
@@ -184,83 +230,103 @@ def handle_commit_workflow()->bool:
|
|
|
184
230
|
commit_result = git_commiter.execute({})
|
|
185
231
|
return commit_result["success"]
|
|
186
232
|
|
|
187
|
-
|
|
233
|
+
|
|
188
234
|
def handle_code_operation(filepath: str, patch_content: str) -> bool:
|
|
235
|
+
"""处理代码操作"""
|
|
236
|
+
if get_file_line_count(filepath) < 30:
|
|
237
|
+
return handle_small_code_operation(filepath, patch_content)
|
|
238
|
+
else:
|
|
239
|
+
return handle_large_code_operation(filepath, patch_content)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def handle_small_code_operation(filepath: str, patch_content: str) -> bool:
|
|
189
243
|
"""处理基于上下文的代码片段"""
|
|
190
244
|
with yaspin(text=f"正在修改文件 {filepath}...", color="cyan") as spinner:
|
|
191
245
|
try:
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
spinner.write("✅ 文件创建完成")
|
|
198
|
-
old_file_content = FileOperationTool().execute({"operation": "read", "files": [{"path": filepath}]})
|
|
199
|
-
if not old_file_content["success"]:
|
|
200
|
-
spinner.write("❌ 文件读取失败")
|
|
201
|
-
return False
|
|
246
|
+
with spinner.hidden():
|
|
247
|
+
old_file_content = FileOperationTool().execute({"operation": "read", "files": [{"path": filepath}]})
|
|
248
|
+
if not old_file_content["success"]:
|
|
249
|
+
spinner.write("❌ 文件读取失败")
|
|
250
|
+
return False
|
|
202
251
|
|
|
203
252
|
prompt = f"""
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
253
|
+
# 代码合并专家指南
|
|
254
|
+
|
|
255
|
+
## 任务描述
|
|
256
|
+
你是一位精确的代码审查与合并专家,需要将补丁内容与原始代码智能合并。
|
|
257
|
+
|
|
258
|
+
## 输入资料
|
|
259
|
+
### 原始代码
|
|
260
|
+
```
|
|
261
|
+
{old_file_content["stdout"]}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### 补丁内容
|
|
265
|
+
```
|
|
266
|
+
{patch_content}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## 合并要求
|
|
270
|
+
1. **精确性**:严格按照补丁的意图修改代码
|
|
271
|
+
2. **完整性**:确保所有需要的更改都被应用
|
|
272
|
+
3. **一致性**:严格保留原始代码的格式、空行和缩进风格
|
|
273
|
+
4. **上下文保留**:保持未修改部分的代码完全不变
|
|
274
|
+
|
|
275
|
+
## 输出格式规范
|
|
276
|
+
- 仅在<MERGED_CODE>标签内输出合并后的完整代码
|
|
277
|
+
- 每次最多输出300行代码
|
|
278
|
+
- 不要使用markdown代码块(```)或反引号,除非修改的是markdown文件
|
|
279
|
+
- 除了合并后的代码,不要输出任何其他文本
|
|
280
|
+
- 所有代码输出完成后,输出<!!!FINISHED!!!>标记
|
|
281
|
+
|
|
282
|
+
## 输出模板
|
|
283
|
+
<MERGED_CODE>
|
|
284
|
+
[合并后的完整代码,包括所有空行和缩进]
|
|
285
|
+
</MERGED_CODE>
|
|
286
|
+
"""
|
|
226
287
|
model = PlatformRegistry().get_codegen_platform()
|
|
227
|
-
model.set_suppress_output(
|
|
288
|
+
model.set_suppress_output(True)
|
|
228
289
|
count = 30
|
|
229
290
|
start_line = -1
|
|
230
291
|
end_line = -1
|
|
231
292
|
code = []
|
|
232
293
|
finished = False
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
start_line = response.index("<MERGED_CODE>") + 1
|
|
239
|
-
except:
|
|
240
|
-
return False
|
|
294
|
+
while count>0:
|
|
295
|
+
count -= 1
|
|
296
|
+
response = model.chat_until_success(prompt).splitlines()
|
|
297
|
+
try:
|
|
298
|
+
start_line = response.index("<MERGED_CODE>") + 1
|
|
241
299
|
try:
|
|
242
300
|
end_line = response.index("</MERGED_CODE>")
|
|
301
|
+
code = response[start_line:end_line]
|
|
243
302
|
except:
|
|
244
|
-
return False
|
|
245
|
-
code = response[start_line:end_line]
|
|
246
|
-
try:
|
|
247
|
-
response.index("<!!!FINISHED!!!>")
|
|
248
|
-
finished = True
|
|
249
|
-
break
|
|
250
|
-
except:
|
|
251
|
-
prompt += f"""继续输出接下来的300行代码
|
|
252
|
-
要求:
|
|
253
|
-
1. 严格保留原始代码的格式、空行和缩进
|
|
254
|
-
2. 仅在<MERGED_CODE>块中包含实际代码内容,包括空行和缩进
|
|
255
|
-
3. 绝对不要使用markdown代码块(```)或反引号,除非修改的是markdown文件
|
|
256
|
-
4. 除了合并后的代码,不要输出任何其他文本
|
|
257
|
-
5. 所有代码输出完成后,输出<!!!FINISHED!!!>
|
|
258
|
-
"""
|
|
259
303
|
pass
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
304
|
+
except:
|
|
305
|
+
pass
|
|
306
|
+
|
|
307
|
+
try:
|
|
308
|
+
response.index("<!!!FINISHED!!!>")
|
|
309
|
+
finished = True
|
|
310
|
+
break
|
|
311
|
+
except:
|
|
312
|
+
prompt += f"""
|
|
313
|
+
# 继续输出
|
|
314
|
+
|
|
315
|
+
## 说明
|
|
316
|
+
请继续输出接下来的300行代码
|
|
317
|
+
|
|
318
|
+
## 要求
|
|
319
|
+
- 严格保留原始代码的格式、空行和缩进
|
|
320
|
+
- 仅在<MERGED_CODE>块中包含实际代码内容
|
|
321
|
+
- 不要使用markdown代码块(```)或反引号
|
|
322
|
+
- 除了合并后的代码,不要输出任何其他文本
|
|
323
|
+
- 所有代码输出完成后,输出<!!!FINISHED!!!>标记
|
|
324
|
+
"""
|
|
325
|
+
pass
|
|
326
|
+
if not finished:
|
|
327
|
+
spinner.text = "生成代码失败"
|
|
328
|
+
spinner.fail("❌")
|
|
329
|
+
return False
|
|
264
330
|
# 写入合并后的代码
|
|
265
331
|
spinner.text = "写入合并后的代码..."
|
|
266
332
|
with open(filepath, 'w', encoding='utf-8') as f:
|
|
@@ -273,3 +339,119 @@ def handle_code_operation(filepath: str, patch_content: str) -> bool:
|
|
|
273
339
|
spinner.text = "代码修改失败"
|
|
274
340
|
spinner.fail("❌")
|
|
275
341
|
return False
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def handle_large_code_operation(filepath: str, patch_content: str) -> bool:
|
|
345
|
+
"""处理大型代码文件的补丁操作,使用差异化补丁格式"""
|
|
346
|
+
with yaspin(text=f"正在处理文件 {filepath}...", color="cyan") as spinner:
|
|
347
|
+
try:
|
|
348
|
+
# 读取原始文件内容
|
|
349
|
+
old_file_content = FileOperationTool().execute({"operation": "read", "files": [{"path": filepath}]})
|
|
350
|
+
if not old_file_content["success"]:
|
|
351
|
+
spinner.text = "文件读取失败"
|
|
352
|
+
spinner.fail("❌")
|
|
353
|
+
return False
|
|
354
|
+
|
|
355
|
+
model = PlatformRegistry().get_codegen_platform()
|
|
356
|
+
model.set_suppress_output(False)
|
|
357
|
+
|
|
358
|
+
prompt = f"""
|
|
359
|
+
# 代码补丁生成专家指南
|
|
360
|
+
|
|
361
|
+
## 任务描述
|
|
362
|
+
你是一位精确的代码补丁生成专家,需要根据补丁描述生成精确的代码差异。
|
|
363
|
+
|
|
364
|
+
## 输入资料
|
|
365
|
+
### 原始代码
|
|
366
|
+
```
|
|
367
|
+
{old_file_content["stdout"]}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### 补丁内容
|
|
371
|
+
```
|
|
372
|
+
{patch_content}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
## 补丁生成要求
|
|
376
|
+
1. **精确性**:严格按照补丁的意图修改代码
|
|
377
|
+
2. **格式一致性**:严格保持原始代码的格式风格
|
|
378
|
+
- 缩进方式(空格或制表符)必须与原代码保持一致
|
|
379
|
+
- 空行数量和位置必须与原代码风格匹配
|
|
380
|
+
- 行尾空格处理必须与原代码一致
|
|
381
|
+
3. **最小化修改**:只修改必要的代码部分,保持其他部分不变
|
|
382
|
+
4. **上下文完整性**:提供足够的上下文,确保补丁能准确应用
|
|
383
|
+
|
|
384
|
+
## 输出格式规范
|
|
385
|
+
- 使用<DIFF>块包围每个需要修改的代码段
|
|
386
|
+
- 每个<DIFF>块必须包含SEARCH部分和REPLACE部分
|
|
387
|
+
- SEARCH部分是需要查找的原始代码
|
|
388
|
+
- REPLACE部分是替换后的新代码
|
|
389
|
+
- 确保SEARCH部分能在原文件中唯一匹配
|
|
390
|
+
- 如果修改较大,可以使用多个<DIFF>块
|
|
391
|
+
|
|
392
|
+
## 输出模板
|
|
393
|
+
<DIFF>
|
|
394
|
+
>>>>>> SEARCH
|
|
395
|
+
[需要查找的原始代码,包含足够上下文]
|
|
396
|
+
======
|
|
397
|
+
[替换后的新代码]
|
|
398
|
+
<<<<<< REPLACE
|
|
399
|
+
</DIFF>
|
|
400
|
+
|
|
401
|
+
<DIFF>
|
|
402
|
+
>>>>>> SEARCH
|
|
403
|
+
[另一处需要查找的原始代码]
|
|
404
|
+
======
|
|
405
|
+
[另一处替换后的新代码]
|
|
406
|
+
<<<<<< REPLACE
|
|
407
|
+
</DIFF>
|
|
408
|
+
"""
|
|
409
|
+
# 获取补丁内容
|
|
410
|
+
with spinner.hidden():
|
|
411
|
+
response = model.chat_until_success(prompt)
|
|
412
|
+
|
|
413
|
+
# 解析差异化补丁
|
|
414
|
+
diff_blocks = re.finditer(r'<DIFF>\s*>{4,} SEARCH\n?(.*?)\n?={4,}\n?(.*?)\s*<{4,} REPLACE\n?</DIFF>',
|
|
415
|
+
response, re.DOTALL)
|
|
416
|
+
|
|
417
|
+
# 读取原始文件内容
|
|
418
|
+
with open(filepath, 'r', encoding='utf-8') as f:
|
|
419
|
+
file_content = f.read()
|
|
420
|
+
|
|
421
|
+
# 应用所有差异化补丁
|
|
422
|
+
modified_content = file_content
|
|
423
|
+
patch_count = 0
|
|
424
|
+
|
|
425
|
+
for match in diff_blocks:
|
|
426
|
+
search_text = match.group(1).strip()
|
|
427
|
+
replace_text = match.group(2).strip()
|
|
428
|
+
|
|
429
|
+
# 检查搜索文本是否存在于文件中
|
|
430
|
+
if search_text in modified_content:
|
|
431
|
+
# 如果有多处,报错
|
|
432
|
+
if modified_content.count(search_text) > 1:
|
|
433
|
+
spinner.text = f"补丁 #{patch_count+1} 应用失败:找到多个匹配的代码段"
|
|
434
|
+
spinner.fail("❌")
|
|
435
|
+
return False
|
|
436
|
+
# 应用替换
|
|
437
|
+
modified_content = modified_content.replace(search_text, replace_text)
|
|
438
|
+
patch_count += 1
|
|
439
|
+
spinner.write(f"✅ 补丁 #{patch_count+1} 应用成功")
|
|
440
|
+
else:
|
|
441
|
+
spinner.text = f"补丁 #{patch_count+1} 应用失败:无法找到匹配的代码段"
|
|
442
|
+
spinner.fail("❌")
|
|
443
|
+
return False
|
|
444
|
+
|
|
445
|
+
# 写入修改后的内容
|
|
446
|
+
with open(filepath, 'w', encoding='utf-8') as f:
|
|
447
|
+
f.write(modified_content)
|
|
448
|
+
|
|
449
|
+
spinner.text = f"文件 {filepath} 修改完成,应用了 {patch_count} 个补丁"
|
|
450
|
+
spinner.ok("✅")
|
|
451
|
+
return True
|
|
452
|
+
|
|
453
|
+
except Exception as e:
|
|
454
|
+
spinner.text = f"文件修改失败: {str(e)}"
|
|
455
|
+
spinner.fail("❌")
|
|
456
|
+
return False
|
|
457
|
+
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from typing import Any, Tuple
|
|
4
4
|
|
|
5
5
|
from jarvis.jarvis_tools.execute_shell_script import ShellScriptTool
|
|
6
|
+
from jarvis.jarvis_tools.registry import ToolRegistry
|
|
6
7
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
7
8
|
from jarvis.jarvis_utils.utils import user_confirm
|
|
8
9
|
|
|
@@ -16,7 +17,12 @@ def shell_input_handler(user_input: str, agent: Any) -> Tuple[str, bool]:
|
|
|
16
17
|
script = '\n'.join([c[1:] for c in cmdline])
|
|
17
18
|
PrettyOutput.print(script, OutputType.CODE, lang="bash")
|
|
18
19
|
if user_confirm(f"是否要执行以上shell脚本?", default=True):
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
output = ToolRegistry().handle_tool_calls({
|
|
21
|
+
"name": "execute_shell_script",
|
|
22
|
+
"arguments": {
|
|
23
|
+
"script_content": script
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
return f"{user_input}\n\n用户执行以下脚本:\n{script}\n\n执行结果:\n{output}", False
|
|
21
27
|
return user_input, False
|
|
22
28
|
|