auto-coder 0.1.325__py3-none-any.whl → 0.1.326__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: auto-coder
3
- Version: 0.1.325
3
+ Version: 0.1.326
4
4
  Summary: AutoCoder: AutoCoder
5
5
  Author: allwefantasy
6
6
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
@@ -14,7 +14,7 @@ autocoder/command_parser.py,sha256=fx1g9E6GaM273lGTcJqaFQ-hoksS_Ik2glBMnVltPCE,1
14
14
  autocoder/lang.py,sha256=U6AjVV8Rs1uLyjFCZ8sT6WWuNUxMBqkXXIOs4S120uk,14511
15
15
  autocoder/models.py,sha256=AyoZ-Pzy0oyYUmWCxOIRiOImsqboSfRET7LO9-UOuxI,11172
16
16
  autocoder/run_context.py,sha256=IUfSO6_gp2Wt1blFWAmOpN0b0nDrTTk4LmtCYUBIoro,1643
17
- autocoder/version.py,sha256=TxojfQzNkFOvmUKL-Ubl0Ef5fbfT55MT6Y10DbUHCPI,23
17
+ autocoder/version.py,sha256=YGdEBe_w43bQfdo8_Mx3DWCOSWhBc0wXQua_nK1cUuo,23
18
18
  autocoder/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  autocoder/agent/auto_demand_organizer.py,sha256=URAq0gSEiHeV_W4zwhOI_83kHz0Ryfj1gcfh5jwCv_w,6501
20
20
  autocoder/agent/auto_filegroup.py,sha256=pBsAkBcpFTff-9L5OwI8xhf2xPKpl-aZwz-skF2B6dc,6296
@@ -102,7 +102,7 @@ autocoder/common/v2/code_auto_merge_diff.py,sha256=xh93G9Gn8zSRhGq6L90tlodFM2u-g
102
102
  autocoder/common/v2/code_auto_merge_editblock.py,sha256=FpXdHAuHhtOLXybrUd2e1rDrxqoge-CpUyWpX0yNEv8,22018
103
103
  autocoder/common/v2/code_auto_merge_strict_diff.py,sha256=jIIedNZGW52dhSmNxb3vB7UdJZp8tg59Z2gg3sCpqoM,10117
104
104
  autocoder/common/v2/code_diff_manager.py,sha256=ciXviNjldX9ce9lgIvmWoG_8JT2GnwRW8U7QCWVdAH0,10512
105
- autocoder/common/v2/code_editblock_manager.py,sha256=AUT_zbawG9nSOrMr68bSfUB5fckSFWMv4yWcBUInyXM,12221
105
+ autocoder/common/v2/code_editblock_manager.py,sha256=vnqXHKSmp6U6Kb1esSO2NRZ7j1Bh5KTaGY6ZxX-6324,11750
106
106
  autocoder/common/v2/code_manager.py,sha256=C403bS-f6urixwitlKHcml-J03hci-UyNwHJOqBiY6Q,9182
107
107
  autocoder/common/v2/code_strict_diff_manager.py,sha256=v-J1kDyLg7tLGg_6_lbO9S4fNkx7M_L8Xr2G7fPptiU,9347
108
108
  autocoder/data/byzerllm.md,sha256=SGCMpEaUQ0ysPxQsgzyyp5sgvEr8dZsxEGAfVcPBIq0,47741
@@ -226,9 +226,9 @@ autocoder/utils/types.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
226
226
  autocoder/utils/auto_coder_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
227
227
  autocoder/utils/auto_coder_utils/chat_stream_out.py,sha256=xuBeWD0YOckqRo8JB1WkVIMOYH6c24m7JfV4svBfPDo,15113
228
228
  autocoder/utils/chat_auto_coder_utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
229
- auto_coder-0.1.325.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
230
- auto_coder-0.1.325.dist-info/METADATA,sha256=lNMC89BQ-3DS6bxOqOqb4EmcgOKZxrqTBp221h4_ac4,2747
231
- auto_coder-0.1.325.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
232
- auto_coder-0.1.325.dist-info/entry_points.txt,sha256=0nzHtHH4pNcM7xq4EBA2toS28Qelrvcbrr59GqD_0Ak,350
233
- auto_coder-0.1.325.dist-info/top_level.txt,sha256=Jqc0_uJSw2GwoFQAa9iJxYns-2mWla-9ok_Y3Gcznjk,10
234
- auto_coder-0.1.325.dist-info/RECORD,,
229
+ auto_coder-0.1.326.dist-info/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
230
+ auto_coder-0.1.326.dist-info/METADATA,sha256=aHhdCGHnZfnbnfXPguIXzw8gTa4xtOPdRMrvr3pjgbs,2747
231
+ auto_coder-0.1.326.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
232
+ auto_coder-0.1.326.dist-info/entry_points.txt,sha256=0nzHtHH4pNcM7xq4EBA2toS28Qelrvcbrr59GqD_0Ak,350
233
+ auto_coder-0.1.326.dist-info/top_level.txt,sha256=Jqc0_uJSw2GwoFQAa9iJxYns-2mWla-9ok_Y3Gcznjk,10
234
+ auto_coder-0.1.326.dist-info/RECORD,,
@@ -39,7 +39,7 @@ class CodeEditBlockManager:
39
39
  It generates code, lints it, and if there are errors, regenerates the code up to 5 times
40
40
  before merging the final result.
41
41
  """
42
-
42
+
43
43
  def __init__(
44
44
  self,
45
45
  llm: byzerllm.ByzerLLM,
@@ -56,11 +56,12 @@ class CodeEditBlockManager:
56
56
  self.generate_times_same_model = args.generate_times_same_model
57
57
  self.max_correction_attempts = args.auto_fix_lint_max_attempts
58
58
  self.printer = Printer()
59
-
59
+
60
60
  # Initialize sub-components
61
- self.code_generator = CodeAutoGenerateEditBlock(llm, args, action, fence_0, fence_1)
61
+ self.code_generator = CodeAutoGenerateEditBlock(
62
+ llm, args, action, fence_0, fence_1)
62
63
  self.code_merger = CodeAutoMergeEditBlock(llm, args, fence_0, fence_1)
63
-
64
+
64
65
  # Create shadow manager for linting
65
66
  self.shadow_manager = ShadowManager(args.source_dir, args.event_file)
66
67
  self.shadow_linter = ShadowLinter(self.shadow_manager, verbose=False)
@@ -72,7 +73,7 @@ class CodeEditBlockManager:
72
73
  <lint_issues>
73
74
  {{ lint_issues }}
74
75
  </lint_issues>
75
-
76
+
76
77
  用户原始需求:
77
78
  <user_query_wrapper>
78
79
  {{ query }}
@@ -81,79 +82,80 @@ class CodeEditBlockManager:
81
82
  修复上述问题,请确保代码质量问题被解决,同时保持代码的原有功能。
82
83
  请严格遵守*SEARCH/REPLACE block*的格式。
83
84
  """
84
-
85
+
85
86
  def _create_shadow_files_from_edits(self, generation_result: CodeGenerateResult) -> Dict[str, str]:
86
87
  """
87
88
  从编辑块内容中提取代码并创建临时影子文件用于检查。
88
-
89
+
89
90
  参数:
90
91
  generation_result (CodeGenerateResult): 包含SEARCH/REPLACE块的内容
91
-
92
+
92
93
  返回:
93
94
  Dict[str, str]: 映射 {影子文件路径: 内容}
94
95
  """
95
96
  result = self.code_merger.choose_best_choice(generation_result)
96
- merge = self.code_merger._merge_code_without_effect(result.contents[0])
97
+ merge = self.code_merger._merge_code_without_effect(result.contents[0])
97
98
  shadow_files = {}
98
99
  for file_path, new_content in merge.success_blocks:
99
100
  self.shadow_manager.update_file(file_path, new_content)
100
- shadow_files[self.shadow_manager.to_shadow_path(file_path)] = new_content
101
+ shadow_files[self.shadow_manager.to_shadow_path(
102
+ file_path)] = new_content
101
103
 
102
104
  return shadow_files
103
105
 
104
- def _format_lint_issues(self, lint_results:ProjectLintResult,levels:List[IssueSeverity]=[IssueSeverity.ERROR]) -> str:
106
+ def _format_lint_issues(self, lint_results: ProjectLintResult, levels: List[IssueSeverity] = [IssueSeverity.ERROR]) -> str:
105
107
  """
106
108
  将linter结果格式化为字符串供模型使用
107
-
109
+
108
110
  参数:
109
111
  lint_results: Linter结果对象
110
112
  level: 过滤问题的级别
111
-
113
+
112
114
  返回:
113
115
  str: 格式化的问题描述
114
116
  """
115
117
  formatted_issues = []
116
-
117
- for file_path, result in lint_results.file_results.items():
118
+
119
+ for file_path, result in lint_results.file_results.items():
118
120
  file_has_issues = False
119
121
  file_issues = []
120
-
121
- for issue in result.issues:
122
+
123
+ for issue in result.issues:
122
124
  if issue.severity.value not in levels:
123
125
  continue
124
-
126
+
125
127
  if not file_has_issues:
126
128
  file_has_issues = True
127
129
  file_issues.append(f"文件: {file_path}")
128
-
130
+
129
131
  severity = "错误" if issue.severity == IssueSeverity.ERROR else "警告" if issue.severity == IssueSeverity.WARNING else "信息"
130
132
  line_info = f"第{issue.position.line}行"
131
133
  if issue.position.column:
132
134
  line_info += f", 第{issue.position.column}列"
133
-
135
+
134
136
  file_issues.append(
135
137
  f" - [{severity}] {line_info}: {issue.message} (规则: {issue.code})"
136
138
  )
137
-
139
+
138
140
  if file_has_issues:
139
141
  formatted_issues.extend(file_issues)
140
142
  formatted_issues.append("") # 空行分隔不同文件
141
-
143
+
142
144
  return "\n".join(formatted_issues)
143
145
 
144
- def _count_errors(self, lint_results:ProjectLintResult,levels:List[IssueSeverity]=[IssueSeverity.ERROR]) -> int:
146
+ def _count_errors(self, lint_results: ProjectLintResult, levels: List[IssueSeverity] = [IssueSeverity.ERROR]) -> int:
145
147
  """
146
148
  计算lint结果中的错误数量
147
-
149
+
148
150
  参数:
149
151
  lint_results: Linter结果对象
150
-
152
+
151
153
  返回:
152
154
  int: 错误数量
153
155
  """
154
156
  error_count = 0
155
-
156
- for _, result in lint_results.file_results.items():
157
+
158
+ for _, result in lint_results.file_results.items():
157
159
  if IssueSeverity.ERROR in levels:
158
160
  error_count += result.error_count
159
161
  if IssueSeverity.WARNING in levels:
@@ -162,25 +164,26 @@ class CodeEditBlockManager:
162
164
  error_count += result.info_count
163
165
  if IssueSeverity.HINT in levels:
164
166
  error_count += result.hint_count
165
-
167
+
166
168
  return error_count
167
169
 
168
170
  def generate_and_fix(self, query: str, source_code_list: SourceCodeList) -> CodeGenerateResult:
169
171
  """
170
172
  生成代码,运行linter,修复错误,最多尝试指定次数
171
-
173
+
172
174
  参数:
173
175
  query (str): 用户查询
174
176
  source_code_list (SourceCodeList): 源代码列表
175
-
177
+
176
178
  返回:
177
179
  CodeGenerateResult: 生成的代码结果
178
180
  """
179
181
  # 初始代码生成
180
182
  self.printer.print_in_terminal("generating_initial_code")
181
183
  start_time = time.time()
182
- generation_result = self.code_generator.single_round_run(query, source_code_list)
183
-
184
+ generation_result = self.code_generator.single_round_run(
185
+ query, source_code_list)
186
+
184
187
  token_cost_calculator = TokenCostCalculator(args=self.args)
185
188
  token_cost_calculator.track_token_usage_by_generate(
186
189
  llm=self.llm,
@@ -189,113 +192,112 @@ class CodeEditBlockManager:
189
192
  start_time=start_time,
190
193
  end_time=time.time()
191
194
  )
192
-
195
+
193
196
  # 确保结果非空
194
197
  if not generation_result.contents:
195
198
  self.printer.print_in_terminal("generation_failed", style="red")
196
199
  return generation_result
197
-
198
-
200
+
199
201
  # 最多尝试修复5次
200
202
  for attempt in range(self.max_correction_attempts):
201
203
  global_cancel.check_and_raise()
202
204
  # 代码生成结果更新到影子文件里去
203
- shadow_files = self._create_shadow_files_from_edits(generation_result)
204
-
205
+ shadow_files = self._create_shadow_files_from_edits(
206
+ generation_result)
207
+
205
208
  if not shadow_files:
206
- self.printer.print_in_terminal("no_files_to_lint", style="yellow")
209
+ self.printer.print_in_terminal(
210
+ "no_files_to_lint", style="yellow")
207
211
  break
208
-
212
+
209
213
  # 运行linter
210
214
  lint_results = self.shadow_linter.lint_all_shadow_files()
211
215
  error_count = self._count_errors(lint_results)
212
216
  # print(f"error_count: {error_count}")
213
- # print(f"lint_results: {json.dumps(lint_results.model_dump(), indent=4,ensure_ascii=False)}")
214
-
217
+ # print(f"lint_results: {json.dumps(lint_results.model_dump(), indent=4,ensure_ascii=False)}")
218
+
215
219
  # 如果没有错误则完成
216
220
  if error_count == 0:
217
- self.printer.print_in_terminal("no_lint_errors_found", style="green")
221
+ self.printer.print_in_terminal(
222
+ "no_lint_errors_found", style="green")
218
223
  break
219
224
 
220
225
  # 格式化lint问题
221
- formatted_issues = self._format_lint_issues(lint_results, [IssueSeverity.ERROR, IssueSeverity.WARNING])
226
+ formatted_issues = self._format_lint_issues(
227
+ lint_results, [IssueSeverity.ERROR, IssueSeverity.WARNING])
222
228
 
223
229
  # 打印当前错误
224
230
  self.printer.print_in_terminal(
225
- "lint_attempt_status",
226
- style="yellow",
227
- attempt=(attempt + 1),
231
+ "lint_attempt_status",
232
+ style="yellow",
233
+ attempt=(attempt + 1),
228
234
  max_correction_attempts=self.max_correction_attempts,
229
235
  error_count=error_count,
230
236
  formatted_issues=formatted_issues
231
237
  )
232
238
 
233
- get_event_manager(self.args.event_file).add_event(Event(
234
- event_type=EventType.RESULT,
235
- content=EventContentCreator.create_result(
236
- content=EventContentCreator.ResultContent(
237
- content=f"Lint attempt {attempt + 1}/{self.max_correction_attempts}: Found {error_count} issues:\n {formatted_issues}",
238
- metadata={}
239
- )
240
- ).to_dict(),
239
+ get_event_manager(self.args.event_file).write_result(EventContentCreator.create_result(
240
+ content=EventContentCreator.ResultContent(content=f"Lint attempt {attempt + 1}/{self.max_correction_attempts}: Found {error_count} issues:\n {formatted_issues}",
241
+ metadata={}
242
+ ).to_dict(),
241
243
  metadata={
242
244
  "stream_out_type": LintStreamOutType.LINT.value,
243
245
  "action_file": self.args.file
244
246
  }
245
247
  ))
246
-
248
+
247
249
  if attempt == self.max_correction_attempts - 1:
248
- self.printer.print_in_terminal("max_attempts_reached", style="yellow")
250
+ self.printer.print_in_terminal(
251
+ "max_attempts_reached", style="yellow")
249
252
  break
250
-
251
-
252
-
253
+
253
254
  # 准备修复提示
254
255
  fix_prompt = self.fix_linter_errors.prompt(
255
256
  query=query,
256
257
  lint_issues=formatted_issues
257
258
  )
258
-
259
+
259
260
  # for source in source_code_list.sources:
260
- # print(f"file_path: {source.module_name}")
261
+ # print(f"file_path: {source.module_name}")
261
262
  # print(f"fix_prompt: {fix_prompt}")
262
-
263
+
263
264
  # 将 shadow_files 转化为 source_code_list
264
265
  start_time = time.time()
265
- source_code_list = self.code_merger.get_source_code_list_from_shadow_files(shadow_files)
266
- generation_result = self.code_generator.single_round_run(fix_prompt, source_code_list)
266
+ source_code_list = self.code_merger.get_source_code_list_from_shadow_files(
267
+ shadow_files)
268
+ generation_result = self.code_generator.single_round_run(
269
+ fix_prompt, source_code_list)
267
270
  token_cost_calculator.track_token_usage_by_generate(
268
271
  llm=self.llm,
269
272
  generate=generation_result,
270
273
  operation_name="code_generation_complete",
271
274
  start_time=start_time,
272
275
  end_time=time.time()
273
- )
276
+ )
274
277
 
275
-
276
278
  # 清理临时影子文件
277
279
  self.shadow_manager.clean_shadows()
278
-
280
+
279
281
  # 返回最终结果
280
282
  return generation_result
281
283
 
282
284
  def run(self, query: str, source_code_list: SourceCodeList) -> CodeGenerateResult:
283
285
  """
284
286
  执行完整的代码生成、修复、合并流程
285
-
287
+
286
288
  参数:
287
289
  query (str): 用户查询
288
290
  source_code_list (SourceCodeList): 源代码列表
289
-
291
+
290
292
  返回:
291
293
  CodeGenerateResult: 生成和修复的代码结果
292
294
  """
293
- # 生成代码并自动修复lint错误
295
+ # 生成代码并自动修复lint错误
294
296
 
295
297
  generation_result = self.generate_and_fix(query, source_code_list)
296
- global_cancel.check_and_raise()
298
+ global_cancel.check_and_raise()
297
299
 
298
- # 合并代码
300
+ # 合并代码
299
301
  self.code_merger.merge_code(generation_result)
300
-
301
- return generation_result
302
+
303
+ return generation_result
autocoder/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.325"
1
+ __version__ = "0.1.326"