jarvis-ai-assistant 0.1.202__py3-none-any.whl → 0.1.203__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 CHANGED
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """Jarvis AI Assistant"""
3
3
 
4
- __version__ = "0.1.202"
4
+ __version__ = "0.1.203"
@@ -1,6 +1,5 @@
1
1
  import os
2
2
  import re
3
- from abc import ABC, abstractmethod
4
3
  from typing import Any, Dict, List, Tuple
5
4
 
6
5
  from yaspin import yaspin
@@ -8,7 +7,6 @@ from yaspin.core import Yaspin
8
7
 
9
8
  from jarvis.jarvis_agent.output_handler import OutputHandler
10
9
  from jarvis.jarvis_platform.registry import PlatformRegistry
11
- from jarvis.jarvis_tools.file_operation import FileOperationTool
12
10
  from jarvis.jarvis_utils.git_utils import revert_file
13
11
  from jarvis.jarvis_utils.output import OutputType, PrettyOutput
14
12
  from jarvis.jarvis_utils.tag import ct, ot
@@ -18,7 +16,7 @@ from jarvis.jarvis_utils.utils import is_context_overflow
18
16
  class EditFileHandler(OutputHandler):
19
17
  def __init__(self):
20
18
  self.patch_pattern = re.compile(
21
- ot("PATCH file=([^>]+)") + r"\s*"
19
+ ot("PATCH file=(?:'([^']+)'|\"([^\"]+)\"|([^>]+))") + r"\s*"
22
20
  r"(?:"
23
21
  + ot("DIFF")
24
22
  + r"\s*"
@@ -69,7 +67,7 @@ class EditFileHandler(OutputHandler):
69
67
  for file_path, diffs in patches.items():
70
68
  file_path = os.path.abspath(file_path)
71
69
  file_patches = [
72
- {"search": diff["search"], "replace": diff["replace"]} for diff in diffs
70
+ {"SEARCH": diff["SEARCH"], "REPLACE": diff["REPLACE"]} for diff in diffs
73
71
  ]
74
72
 
75
73
  with yaspin(text=f"正在处理文件 {file_path}...", color="cyan") as spinner:
@@ -132,6 +130,7 @@ class EditFileHandler(OutputHandler):
132
130
  该方法使用正则表达式从响应文本中提取文件编辑指令(PATCH块),
133
131
  每个PATCH块可以包含多个DIFF块,每个DIFF块包含一组搜索和替换内容。
134
132
  解析后会返回一个字典,键是文件路径,值是该文件对应的补丁列表。
133
+ 如果同一个文件路径出现多次,会将所有DIFF块合并到一起。
135
134
 
136
135
  Args:
137
136
  response: 包含补丁信息的响应字符串,格式应符合PATCH指令规范
@@ -141,25 +140,29 @@ class EditFileHandler(OutputHandler):
141
140
  返回解析后的补丁信息字典,结构为:
142
141
  {
143
142
  "文件路径1": [
144
- {"search": "搜索文本1", "replace": "替换文本1"},
145
- {"search": "搜索文本2", "replace": "替换文本2"}
143
+ {"SEARCH": "搜索文本1", "REPLACE": "替换文本1"},
144
+ {"SEARCH": "搜索文本2", "REPLACE": "替换文本2"}
146
145
  ],
147
146
  "文件路径2": [...]
148
147
  }
149
148
  """
150
149
  patches = {}
151
150
  for match in self.patch_pattern.finditer(response):
152
- file_path = match.group(1)
151
+ # Get the file path from the appropriate capture group
152
+ file_path = match.group(1) or match.group(2) or match.group(3)
153
153
  diffs = []
154
154
  for diff_match in self.diff_pattern.finditer(match.group(0)):
155
155
  diffs.append(
156
156
  {
157
- "search": diff_match.group(1).strip(),
158
- "replace": diff_match.group(2).strip(),
157
+ "SEARCH": diff_match.group(1).strip(),
158
+ "REPLACE": diff_match.group(2).strip(),
159
159
  }
160
160
  )
161
161
  if diffs:
162
- patches[file_path] = diffs
162
+ if file_path in patches:
163
+ patches[file_path].extend(diffs)
164
+ else:
165
+ patches[file_path] = diffs
163
166
  return patches
164
167
 
165
168
  @staticmethod
@@ -199,12 +202,16 @@ class EditFileHandler(OutputHandler):
199
202
  modified_content = file_content
200
203
  patch_count = 0
201
204
  for patch in patches:
202
- search_text = patch["search"]
203
- replace_text = patch["replace"]
205
+ search_text = patch["SEARCH"]
206
+ replace_text = patch["REPLACE"]
204
207
  patch_count += 1
205
208
 
206
209
  if search_text in modified_content:
207
210
  if modified_content.count(search_text) > 1:
211
+ PrettyOutput.print(
212
+ f"搜索文本在文件中存在多处匹配:\n{search_text}",
213
+ output_type=OutputType.WARNING,
214
+ )
208
215
  return False, f"搜索文本在文件中存在多处匹配:\n{search_text}"
209
216
  modified_content = modified_content.replace(
210
217
  search_text, replace_text
@@ -224,6 +231,10 @@ class EditFileHandler(OutputHandler):
224
231
  )
225
232
  if indented_search in modified_content:
226
233
  if modified_content.count(indented_search) > 1:
234
+ PrettyOutput.print(
235
+ f"搜索文本在文件中存在多处匹配:\n{indented_search}",
236
+ output_type=OutputType.WARNING,
237
+ )
227
238
  return (
228
239
  False,
229
240
  f"搜索文本在文件中存在多处匹配:\n{indented_search}",
@@ -238,6 +249,10 @@ class EditFileHandler(OutputHandler):
238
249
  break
239
250
 
240
251
  if not found:
252
+ PrettyOutput.print(
253
+ f"搜索文本在文件中不存在:\n{search_text}",
254
+ output_type=OutputType.WARNING,
255
+ )
241
256
  return False, f"搜索文本在文件中不存在:\n{search_text}"
242
257
 
243
258
  # 写入修改后的内容
@@ -308,8 +323,8 @@ class EditFileHandler(OutputHandler):
308
323
  patch_content.append(
309
324
  {
310
325
  "reason": "根据用户指令修改代码",
311
- "search": patch["search"],
312
- "replace": patch["replace"],
326
+ "SEARCH": patch["SEARCH"],
327
+ "REPLACE": patch["REPLACE"],
313
328
  }
314
329
  )
315
330
 
@@ -390,8 +405,8 @@ class EditFileHandler(OutputHandler):
390
405
  for match in diff_blocks:
391
406
  generated_patches.append(
392
407
  {
393
- "search": match.group(1).strip(),
394
- "replace": match.group(2).strip(),
408
+ "SEARCH": match.group(1).strip(),
409
+ "REPLACE": match.group(2).strip(),
395
410
  }
396
411
  )
397
412
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.202
3
+ Version: 0.1.203
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
@@ -1,7 +1,7 @@
1
- jarvis/__init__.py,sha256=1uYZEHP44b3jLJZ5d-Ydy94aetzbjTE6KoKfy3CdhSc,75
1
+ jarvis/__init__.py,sha256=6vjQIk71IT0f_EPgzrHvjWl2bp3n_NOJMy-NtNfAZ-g,75
2
2
  jarvis/jarvis_agent/__init__.py,sha256=X5BWIOzxXUWtCbpDkTFfUYskf6sbNzb1qQu8nQ4NN1k,34371
3
3
  jarvis/jarvis_agent/builtin_input_handler.py,sha256=1V7kV5Zhw2HE3Xgjs1R-43RZ2huq3Kg-32NCdNnyZmA,2216
4
- jarvis/jarvis_agent/edit_file_handler.py,sha256=ZDHjtggwFrHAOcfOAScKyPHSw9a3NvbKRqRtHjp2w9Q,15545
4
+ jarvis/jarvis_agent/edit_file_handler.py,sha256=EVEKZUon2CbLHQ1id1_5nka_oGJALGv1k1jmKJva3JA,16478
5
5
  jarvis/jarvis_agent/jarvis.py,sha256=GH2zi8eXNpW8twiY3LKDEZgGmFC5geB0jlkwFrm7hOQ,6279
6
6
  jarvis/jarvis_agent/main.py,sha256=c6bQe-8LXvW2-NBn9Rn_yPYdrwnkJ8KQaSFY2cPvkxw,2775
7
7
  jarvis/jarvis_agent/output_handler.py,sha256=P7oWpXBGFfOsWq7cIhS_z9crkQ19ES7qU5pM92KKjAs,1172
@@ -91,9 +91,9 @@ jarvis/jarvis_utils/methodology.py,sha256=MhPrMxMqElyAn54BDfpQdUqrRr7IbSlrLvAI39
91
91
  jarvis/jarvis_utils/output.py,sha256=PRCgudPOB8gMEP3u-g0FGD2c6tBgJhLXUMqNPglfjV8,10813
92
92
  jarvis/jarvis_utils/tag.py,sha256=f211opbbbTcSyzCDwuIK_oCnKhXPNK-RknYyGzY1yD0,431
93
93
  jarvis/jarvis_utils/utils.py,sha256=RYFQx7OkOu3fe_QhS-5jx7O06k_58X14S-9PFJgwOa4,12178
94
- jarvis_ai_assistant-0.1.202.dist-info/licenses/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
95
- jarvis_ai_assistant-0.1.202.dist-info/METADATA,sha256=7i5-nQ4XDVbIBrfSebmIaqMOKN6GzZot2a4pJ1OJ_AQ,20215
96
- jarvis_ai_assistant-0.1.202.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
97
- jarvis_ai_assistant-0.1.202.dist-info/entry_points.txt,sha256=Gy3DOP1PYLMK0GCj4rrP_9lkOyBQ39EK_lKGUSwn41E,869
98
- jarvis_ai_assistant-0.1.202.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
99
- jarvis_ai_assistant-0.1.202.dist-info/RECORD,,
94
+ jarvis_ai_assistant-0.1.203.dist-info/licenses/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
95
+ jarvis_ai_assistant-0.1.203.dist-info/METADATA,sha256=Z2KYARBymf4cu82o1L_vXEo8KXujcOUkbFnb8qZx5Lc,20215
96
+ jarvis_ai_assistant-0.1.203.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
97
+ jarvis_ai_assistant-0.1.203.dist-info/entry_points.txt,sha256=Gy3DOP1PYLMK0GCj4rrP_9lkOyBQ39EK_lKGUSwn41E,869
98
+ jarvis_ai_assistant-0.1.203.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
99
+ jarvis_ai_assistant-0.1.203.dist-info/RECORD,,