auto-coder 0.1.316__py3-none-any.whl → 0.1.317__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 auto-coder might be problematic. Click here for more details.

Files changed (41) hide show
  1. {auto_coder-0.1.316.dist-info → auto_coder-0.1.317.dist-info}/METADATA +1 -1
  2. {auto_coder-0.1.316.dist-info → auto_coder-0.1.317.dist-info}/RECORD +41 -20
  3. autocoder/auto_coder_runner.py +1 -2
  4. autocoder/common/__init__.py +3 -0
  5. autocoder/common/auto_coder_lang.py +24 -0
  6. autocoder/common/code_auto_merge_editblock.py +2 -42
  7. autocoder/common/git_utils.py +2 -2
  8. autocoder/common/token_cost_caculate.py +103 -42
  9. autocoder/common/v2/__init__.py +0 -0
  10. autocoder/common/v2/code_auto_generate.py +199 -0
  11. autocoder/common/v2/code_auto_generate_diff.py +361 -0
  12. autocoder/common/v2/code_auto_generate_editblock.py +380 -0
  13. autocoder/common/v2/code_auto_generate_strict_diff.py +269 -0
  14. autocoder/common/v2/code_auto_merge.py +211 -0
  15. autocoder/common/v2/code_auto_merge_diff.py +354 -0
  16. autocoder/common/v2/code_auto_merge_editblock.py +523 -0
  17. autocoder/common/v2/code_auto_merge_strict_diff.py +259 -0
  18. autocoder/common/v2/code_diff_manager.py +266 -0
  19. autocoder/common/v2/code_editblock_manager.py +275 -0
  20. autocoder/common/v2/code_manager.py +238 -0
  21. autocoder/common/v2/code_strict_diff_manager.py +241 -0
  22. autocoder/dispacher/actions/action.py +16 -0
  23. autocoder/dispacher/actions/plugins/action_regex_project.py +6 -0
  24. autocoder/events/event_manager_singleton.py +2 -2
  25. autocoder/helper/__init__.py +0 -0
  26. autocoder/helper/project_creator.py +570 -0
  27. autocoder/linters/linter_factory.py +44 -25
  28. autocoder/linters/models.py +220 -0
  29. autocoder/linters/python_linter.py +1 -7
  30. autocoder/linters/reactjs_linter.py +580 -0
  31. autocoder/linters/shadow_linter.py +390 -0
  32. autocoder/linters/vue_linter.py +576 -0
  33. autocoder/memory/active_context_manager.py +0 -4
  34. autocoder/memory/active_package.py +12 -12
  35. autocoder/shadows/__init__.py +0 -0
  36. autocoder/shadows/shadow_manager.py +235 -0
  37. autocoder/version.py +1 -1
  38. {auto_coder-0.1.316.dist-info → auto_coder-0.1.317.dist-info}/LICENSE +0 -0
  39. {auto_coder-0.1.316.dist-info → auto_coder-0.1.317.dist-info}/WHEEL +0 -0
  40. {auto_coder-0.1.316.dist-info → auto_coder-0.1.317.dist-info}/entry_points.txt +0 -0
  41. {auto_coder-0.1.316.dist-info → auto_coder-0.1.317.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,235 @@
1
+ import os
2
+ import shutil
3
+
4
+ class ShadowManager:
5
+ """
6
+ 管理项目文件/目录与其影子等效项之间的映射。
7
+ 影子文件/目录存储在<source_dir>/.auto-coder/shadows/中,
8
+ 并镜像原始项目的结构。
9
+
10
+ 如果提供了event_file_id,则影子文件存储在<source_dir>/.auto-coder/shadows/<event_file_id>/中。
11
+ """
12
+
13
+ def __init__(self, source_dir, event_file_id=None):
14
+ """
15
+ 使用项目根目录初始化。
16
+
17
+ 参数:
18
+ source_dir (str): 项目根目录的绝对路径。
19
+ event_file_id (str, optional): 事件文件ID,用于创建特定的影子目录。
20
+ """
21
+ self.source_dir = os.path.abspath(source_dir)
22
+
23
+ # 根据是否提供了event_file_id来确定shadows_dir的路径
24
+ if event_file_id:
25
+ event_file_id = self.get_event_file_id_from_path(event_file_id)
26
+ self.shadows_dir = os.path.join(self.source_dir, '.auto-coder', 'shadows', event_file_id)
27
+ else:
28
+ self.shadows_dir = os.path.join(self.source_dir, '.auto-coder', 'shadows')
29
+
30
+ # 确保影子目录存在
31
+ os.makedirs(self.shadows_dir, exist_ok=True)
32
+
33
+ def get_event_file_id_from_path(self, path):
34
+ """
35
+ 从给定路径中提取事件文件ID。
36
+
37
+ 参数:
38
+ path (str): 项目路径
39
+
40
+ 返回:
41
+ str: 事件文件ID
42
+ """
43
+ if not path.endswith('.jsonl'):
44
+ return event_file_id
45
+ temp = os.path.basename(path)
46
+ ## 获取不带后缀的event_file_id
47
+ event_file_id = os.path.splitext(temp)[0]
48
+ return event_file_id
49
+
50
+ def to_shadow_path(self, path):
51
+ """
52
+ 将项目路径转换为其影子等效路径。
53
+
54
+ 参数:
55
+ path (str): 源目录内的路径(绝对或相对)
56
+
57
+ 返回:
58
+ str: 对应影子位置的绝对路径
59
+
60
+ 异常:
61
+ ValueError: 如果路径不在源目录内
62
+ """
63
+ # 确保我们有一个绝对路径
64
+ abs_path = os.path.abspath(path)
65
+
66
+ # 检查路径是否在源目录内
67
+ if not abs_path.startswith(self.source_dir):
68
+ raise ValueError(f"路径 {path} 不在源目录 {self.source_dir} 内")
69
+
70
+ # 获取相对于source_dir的相对路径
71
+ rel_path = os.path.relpath(abs_path, self.source_dir)
72
+
73
+ # 创建影子路径
74
+ shadow_path = os.path.join(self.shadows_dir, rel_path)
75
+
76
+ return shadow_path
77
+
78
+ def from_shadow_path(self, shadow_path):
79
+ """
80
+ 将影子路径转换回其项目等效路径。
81
+
82
+ 参数:
83
+ shadow_path (str): 影子目录内的路径(绝对或相对)
84
+
85
+ 返回:
86
+ str: 对应项目位置的绝对路径
87
+
88
+ 异常:
89
+ ValueError: 如果路径不在影子目录内
90
+ """
91
+ # 确保我们有一个绝对路径
92
+ abs_shadow_path = os.path.abspath(shadow_path)
93
+
94
+ # 检查路径是否在影子目录内
95
+ if not abs_shadow_path.startswith(self.shadows_dir):
96
+ raise ValueError(f"路径 {shadow_path} 不在影子目录 {self.shadows_dir} 内")
97
+
98
+ # 获取相对于shadows_dir的相对路径
99
+ rel_path = os.path.relpath(abs_shadow_path, self.shadows_dir)
100
+
101
+ # 创建项目路径
102
+ project_path = os.path.join(self.source_dir, rel_path)
103
+
104
+ return project_path
105
+
106
+ def ensure_shadow_dir_exists(self, path):
107
+ """
108
+ 确保给定路径的影子目录存在。
109
+
110
+ 参数:
111
+ path (str): 需要创建影子目录的项目路径
112
+
113
+ 返回:
114
+ str: 影子路径
115
+ """
116
+ shadow_path = self.to_shadow_path(path)
117
+
118
+ if os.path.isdir(path):
119
+ os.makedirs(shadow_path, exist_ok=True)
120
+ else:
121
+ os.makedirs(os.path.dirname(shadow_path), exist_ok=True)
122
+
123
+ return shadow_path
124
+
125
+ def is_shadow_path(self, path):
126
+ """
127
+ 检查路径是否为影子路径。
128
+
129
+ 参数:
130
+ path (str): 要检查的路径
131
+
132
+ 返回:
133
+ bool: 如果路径在影子目录内,则为True
134
+ """
135
+ abs_path = os.path.abspath(path)
136
+ return abs_path.startswith(self.shadows_dir)
137
+
138
+ def save_file(self, file_path, content):
139
+ """
140
+ 将内容保存到对应给定项目文件路径的影子文件中。
141
+
142
+ 参数:
143
+ file_path (str): 项目文件路径
144
+ content (str): 要保存的内容
145
+
146
+ 返回:
147
+ str: 保存内容的影子路径
148
+ """
149
+ shadow_path = self.to_shadow_path(file_path)
150
+
151
+ # 确保父目录存在
152
+ os.makedirs(os.path.dirname(shadow_path), exist_ok=True)
153
+
154
+ # 将内容写入影子文件
155
+ with open(shadow_path, 'w', encoding='utf-8') as f:
156
+ f.write(content)
157
+
158
+ return shadow_path
159
+
160
+ def update_file(self, file_path, content):
161
+ """
162
+ 更新对应给定项目文件路径的影子文件。
163
+ 如果影子文件不存在,将创建它。
164
+
165
+ 参数:
166
+ file_path (str): 项目文件路径
167
+ content (str): 要更新的内容
168
+
169
+ 返回:
170
+ str: 更新内容的影子路径
171
+ """
172
+ # 此实现本质上与save_file相同
173
+ return self.save_file(file_path, content)
174
+
175
+ def read_file(self, file_path):
176
+ """
177
+ 从对应给定项目文件路径的影子文件中读取内容。
178
+
179
+ 参数:
180
+ file_path (str): 项目文件路径
181
+
182
+ 返回:
183
+ str: 影子文件的内容
184
+
185
+ 异常:
186
+ FileNotFoundError: 如果影子文件不存在
187
+ """
188
+ shadow_path = self.to_shadow_path(file_path)
189
+
190
+ with open(shadow_path, 'r', encoding='utf-8') as f:
191
+ content = f.read()
192
+
193
+ return content
194
+
195
+ def delete_file(self, file_path):
196
+ """
197
+ 删除对应给定项目文件路径的影子文件。
198
+
199
+ 参数:
200
+ file_path (str): 项目文件路径
201
+
202
+ 返回:
203
+ bool: 如果文件被删除则为True,如果不存在则为False
204
+ """
205
+ shadow_path = self.to_shadow_path(file_path)
206
+
207
+ if os.path.exists(shadow_path):
208
+ os.remove(shadow_path)
209
+ return True
210
+
211
+ return False
212
+
213
+ def clean_shadows(self):
214
+ """
215
+ 清理影子目录中的所有文件和子目录,但保留影子目录本身。
216
+
217
+ 返回:
218
+ bool: 操作成功则为True,否则为False
219
+ """
220
+ if not os.path.exists(self.shadows_dir):
221
+ return True
222
+
223
+ try:
224
+ # 删除影子目录中的所有内容
225
+ for item in os.listdir(self.shadows_dir):
226
+ item_path = os.path.join(self.shadows_dir, item)
227
+ if os.path.isfile(item_path):
228
+ os.unlink(item_path)
229
+ elif os.path.isdir(item_path):
230
+ shutil.rmtree(item_path)
231
+
232
+ return True
233
+ except Exception as e:
234
+ print(f"清理影子目录时出错: {str(e)}")
235
+ return False
autocoder/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.316"
1
+ __version__ = "0.1.317"