auto-coder 0.1.354__py3-none-any.whl → 0.1.356__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 (40) hide show
  1. {auto_coder-0.1.354.dist-info → auto_coder-0.1.356.dist-info}/METADATA +1 -1
  2. {auto_coder-0.1.354.dist-info → auto_coder-0.1.356.dist-info}/RECORD +40 -35
  3. autocoder/agent/agentic_filter.py +1 -1
  4. autocoder/agent/auto_learn.py +631 -0
  5. autocoder/auto_coder.py +8 -0
  6. autocoder/auto_coder_runner.py +59 -87
  7. autocoder/chat/conf_command.py +270 -0
  8. autocoder/chat/models_command.py +485 -0
  9. autocoder/chat/rules_command.py +458 -0
  10. autocoder/chat_auto_coder.py +34 -24
  11. autocoder/chat_auto_coder_lang.py +156 -2
  12. autocoder/commands/auto_command.py +1 -1
  13. autocoder/commands/auto_web.py +1 -1
  14. autocoder/common/__init__.py +2 -0
  15. autocoder/common/auto_coder_lang.py +9 -1
  16. autocoder/common/command_completer.py +58 -12
  17. autocoder/common/command_completer_v2.py +615 -0
  18. autocoder/common/global_cancel.py +53 -16
  19. autocoder/common/rulefiles/autocoderrules_utils.py +83 -0
  20. autocoder/common/v2/agent/agentic_edit.py +4 -4
  21. autocoder/common/v2/code_agentic_editblock_manager.py +9 -9
  22. autocoder/common/v2/code_diff_manager.py +2 -2
  23. autocoder/common/v2/code_editblock_manager.py +11 -10
  24. autocoder/common/v2/code_strict_diff_manager.py +3 -2
  25. autocoder/dispacher/actions/action.py +6 -6
  26. autocoder/dispacher/actions/plugins/action_regex_project.py +2 -2
  27. autocoder/events/event_manager_singleton.py +1 -1
  28. autocoder/index/index.py +2 -2
  29. autocoder/rag/cache/local_byzer_storage_cache.py +1 -1
  30. autocoder/rag/cache/local_duckdb_storage_cache.py +8 -0
  31. autocoder/rag/loaders/image_loader.py +25 -13
  32. autocoder/rag/long_context_rag.py +2 -2
  33. autocoder/utils/auto_coder_utils/chat_stream_out.py +3 -4
  34. autocoder/utils/model_provider_selector.py +14 -2
  35. autocoder/utils/thread_utils.py +9 -27
  36. autocoder/version.py +1 -1
  37. {auto_coder-0.1.354.dist-info → auto_coder-0.1.356.dist-info}/LICENSE +0 -0
  38. {auto_coder-0.1.354.dist-info → auto_coder-0.1.356.dist-info}/WHEEL +0 -0
  39. {auto_coder-0.1.354.dist-info → auto_coder-0.1.356.dist-info}/entry_points.txt +0 -0
  40. {auto_coder-0.1.354.dist-info → auto_coder-0.1.356.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,631 @@
1
+ from typing import Generator, List, Dict, Union, Tuple, Optional
2
+ import os
3
+ import byzerllm
4
+ import pydantic
5
+ import git
6
+ from rich.console import Console
7
+ from autocoder.common.printer import Printer
8
+ from autocoder.common import AutoCoderArgs
9
+ from autocoder.common.utils_code_auto_generate import stream_chat_with_continue
10
+ from autocoder.common import SourceCode, SourceCodeList
11
+ from autocoder.common.action_yml_file_manager import ActionYmlFileManager
12
+
13
+
14
+ class AutoLearn:
15
+ def __init__(self, llm: Union[byzerllm.ByzerLLM, byzerllm.SimpleByzerLLM],
16
+ args: AutoCoderArgs,
17
+ console: Optional[Console] = None):
18
+ """
19
+ 初始化 AutoLearn
20
+
21
+ Args:
22
+ llm: ByzerLLM 实例,用于代码分析和学习
23
+ args: AutoCoderArgs 实例,包含配置信息
24
+ console: Rich Console 实例,用于输出
25
+ """
26
+ self.llm = llm
27
+ self.args = args
28
+ self.console = console or Console()
29
+ self.printer = Printer()
30
+
31
+ @byzerllm.prompt()
32
+ def analyze_commit(self,
33
+ querie_with_urls_and_changes: List[Tuple[str, List[str], Dict[str, Tuple[str, str]]]],
34
+ new_query:str,
35
+ ) -> str:
36
+ """
37
+ 作为高级软件工程师,请对提供的代码提交变更进行深入分析,提取具有通用价值的功能模式和设计模式,转化为可在其他项目中复用的代码规则(rules)。
38
+
39
+ ## 任务目标
40
+ - 识别代码变更中具有普遍应用价值的功能点和模式
41
+ - 将这些功能点提炼为结构化规则,便于在其他项目中快速复用
42
+ - 生成清晰的使用示例,包含完整依赖和调用方式
43
+ - 这些规则将被存储在项目的 .autocoderrules 目录,供后续自动化代码生成使用
44
+
45
+ 项目根目录: {{ project_root }}
46
+
47
+ ## 分析对象
48
+ 下面是本次提交的代码变更:
49
+ <changes>
50
+ {% for query,urls,changes in querie_with_urls_and_changes %}
51
+ ## 原始的任务需求
52
+ {{ query }}
53
+
54
+ 修改的文件:
55
+ {% for url in urls %}
56
+ - {{ url }}
57
+ {% endfor %}
58
+
59
+ 代码变更:
60
+ {% for file_path, (before, after) in changes.items() %}
61
+ ##File: {{ file_path }}
62
+ ##修改前:
63
+
64
+ {{ before or "New file" }}
65
+
66
+ ##File: {{ file_path }}
67
+ ##修改后:
68
+
69
+ {{ after or "File deleted" }}
70
+
71
+ {% endfor %}
72
+ {% endfor %}
73
+ </changes>
74
+
75
+ {% if index_file_content %}
76
+ ## 现有索引内容
77
+ index.md 当前内容:
78
+ <files>
79
+ <file>
80
+ ##File:
81
+ {{ index_file_content }}
82
+ </file>
83
+ </files>
84
+ {% endif %}
85
+
86
+ ## 用户需求
87
+ {{ new_query }}
88
+
89
+ ## 输出格式要求
90
+
91
+ 请按照以下结构(<markdown>...</markdown>包裹的内容)输出规则文件内容:
92
+
93
+ <markdown>
94
+ ---
95
+ description: [简明描述规则的功能,20字以内]
96
+ globs: [匹配应用此规则的文件路径,如"src/services/*.py"]
97
+ alwaysApply: [是否总是应用,通常为false]
98
+ ---
99
+
100
+ # [规则主标题]
101
+
102
+ ## 简要说明
103
+ [该规则的功能、适用场景和价值,100字以内]
104
+
105
+ ## 典型用法
106
+ ```python
107
+ # 完整的代码示例,包含:
108
+ # 1. 必要的import语句
109
+ # 2. 类/函数定义
110
+ # 3. 参数说明
111
+ # 4. 调用方式
112
+ # 5. 关键注释
113
+ ```
114
+
115
+ ## 依赖说明
116
+ - [必要的依赖库及版本]
117
+ - [环境要求]
118
+ - [初始化流程(如有)]
119
+
120
+ ## 学习来源
121
+ [从哪个提交变更的哪部分代码中提取的该功能点]
122
+ </markdown>
123
+
124
+ ## 示例
125
+
126
+ <markdown>
127
+ ---
128
+ description: Git提交分析工具
129
+ globs: "src/utils/git_analyzer.py"
130
+ alwaysApply: false
131
+ ---
132
+
133
+ # Git提交分析工具
134
+
135
+ ## 简要说明
136
+ 提供从Git仓库中获取提交变更并分析差异的工具函数,支持首次提交和普通提交的差异获取,适用于代码审查、变更追踪和自动化分析场景。
137
+
138
+ ## 典型用法
139
+ ```python
140
+ import git
141
+ from typing import Dict, Tuple, List, Optional
142
+
143
+ def get_commit_changes(repo_path: str, commit_id: str) -> Dict[str, Tuple[Optional[str], Optional[str]]]:
144
+ '''
145
+ 获取指定commit的文件变更内容
146
+
147
+ Args:
148
+ repo_path: Git仓库路径
149
+ commit_id: 提交ID
150
+
151
+ Returns:
152
+ Dict[str, Tuple[Optional[str], Optional[str]]]: 文件路径到(变更前内容,变更后内容)的映射
153
+ '''
154
+ changes = {}
155
+ try:
156
+ repo = git.Repo(repo_path)
157
+ commit = repo.commit(commit_id)
158
+
159
+ # 检查是否是首次提交(没有父提交)
160
+ if not commit.parents:
161
+ # 首次提交,获取所有文件
162
+ for item in commit.tree.traverse():
163
+ if item.type == 'blob': # 只处理文件,不处理目录
164
+ file_path = item.path
165
+ # 首次提交前没有内容
166
+ before_content = None
167
+ # 获取提交后的内容
168
+ after_content = repo.git.show(f"{commit.hexsha}:{file_path}")
169
+ changes[file_path] = (before_content, after_content)
170
+ else:
171
+ # 获取parent commit
172
+ parent = commit.parents[0]
173
+ # 获取变更的文件列表
174
+ for diff_item in parent.diff(commit):
175
+ file_path = diff_item.a_path if diff_item.a_path else diff_item.b_path
176
+
177
+ # 获取变更前内容
178
+ before_content = None
179
+ try:
180
+ if diff_item.a_blob:
181
+ before_content = repo.git.show(f"{parent.hexsha}:{file_path}")
182
+ except git.exc.GitCommandError:
183
+ pass # 文件可能是新增的
184
+
185
+ # 获取变更后内容
186
+ after_content = None
187
+ try:
188
+ if diff_item.b_blob:
189
+ after_content = repo.git.show(f"{commit.hexsha}:{file_path}")
190
+ except git.exc.GitCommandError:
191
+ pass # 文件可能被删除
192
+
193
+ changes[file_path] = (before_content, after_content)
194
+
195
+ return changes
196
+ except Exception as e:
197
+ print(f"获取提交变更时出错: {str(e)}")
198
+ return {}
199
+ ```
200
+
201
+ ## 依赖说明
202
+ - GitPython>=3.1.0
203
+ - Python>=3.7
204
+
205
+ ## 学习来源
206
+ 从代码提交变更中提取的Git仓库差异分析功能
207
+ </markdown>
208
+
209
+ ## 索引文件更新说明
210
+
211
+ 除了生成规则文件外,请务必更新index.md索引文件,记录所有规则及其作用。如果 index.md 当前内容为空,请按如下格式创建:
212
+
213
+ <markdown>
214
+ # Rules索引
215
+
216
+ 本文档记录项目中所有可用的代码规则(rules)及其用途。
217
+
218
+ ## [规则文件路径]
219
+ [规则文件的主要功能和适用场景简述]
220
+ </markdown>
221
+
222
+ ## 评价标准
223
+ - 提取的功能点必须具备独立价值,能在其他项目中实际复用
224
+ - 代码示例必须完整、可执行,包含所有必要组件
225
+ - 文档结构清晰,遵循规定格式
226
+ - 依赖说明明确具体,便于用户快速配置环境
227
+ """
228
+ return {
229
+ "project_root": os.path.abspath(self.args.source_dir),
230
+ "index_file_content": self._get_index_file_content()
231
+ }
232
+
233
+ @byzerllm.prompt()
234
+ def analyze_modules(self, sources: SourceCodeList, query: str) -> str:
235
+ """
236
+ 作为高级软件工程师,请对提供的模块代码进行深入分析,提取具有通用价值的功能模式和设计模式,转化为可在其他项目中复用的代码规则(rules)。
237
+
238
+ ## 任务目标
239
+ - 识别代码中具有普遍应用价值的功能点和模式
240
+ - 将这些功能点提炼为结构化规则,便于在其他项目中快速复用
241
+ - 生成清晰的使用示例,包含完整依赖和调用方式
242
+ - 这些规则将被存储在项目的 .autocoderrules 目录,供后续自动化代码生成使用
243
+
244
+ 项目根目录: {{ project_root }}
245
+
246
+ ## 分析对象
247
+ {% if sources.sources %}
248
+ 分析目标文件:
249
+ {% for source in sources.sources %}
250
+ - {{ source.module_name }}
251
+ {% endfor %}
252
+ {% else %}
253
+ 前面提供的文件。
254
+ {% endif %}
255
+
256
+ {% if sources.sources %}
257
+ ## 源代码内容
258
+ <files>
259
+ {% for source in sources.sources %}
260
+ ##File: {{ source.module_name }}
261
+ {{ source.source_code }}
262
+ {% endfor %}
263
+ </files>
264
+ {% endif %}
265
+
266
+ {% if index_file_content %}
267
+ ## 现有索引内容
268
+ index.md 当前内容:
269
+ <files>
270
+ <file>
271
+ ##File:
272
+ {{ index_file_content }}
273
+ </file>
274
+ </files>
275
+ {% endif %}
276
+
277
+ ## 用户需求
278
+ {{ query }}
279
+
280
+ ## 输出格式要求
281
+
282
+ 请按照以下结构(<markdown>...</markdown>包裹的内容)输出规则文件内容:
283
+
284
+ <markdown>
285
+ ---
286
+ description: [简明描述规则的功能,20字以内]
287
+ globs: [匹配应用此规则的文件路径,如"src/services/*.py"]
288
+ alwaysApply: [是否总是应用,通常为false]
289
+ ---
290
+
291
+ # [规则主标题]
292
+
293
+ ## 简要说明
294
+ [该规则的功能、适用场景和价值,100字以内]
295
+
296
+ ## 典型用法
297
+ ```python
298
+ # 完整的代码示例,包含:
299
+ # 1. 必要的import语句
300
+ # 2. 类/函数定义
301
+ # 3. 参数说明
302
+ # 4. 调用方式
303
+ # 5. 关键注释
304
+
305
+ ## 依赖说明
306
+ - [必要的依赖库及版本]
307
+ - [环境要求]
308
+ - [初始化流程(如有)]
309
+
310
+ ## 学习来源
311
+ [从哪个模块的哪部分代码中提取的该功能点]
312
+ </markdown>
313
+
314
+ ## 示例
315
+
316
+ <markdown>
317
+ ---
318
+ description: RPC服务模板
319
+ globs: "src/services/rpc_service.py"
320
+ alwaysApply: false
321
+ ---
322
+
323
+ # RPC服务快速实现模板
324
+
325
+ ## 简要说明
326
+ 提供gRPC服务端与客户端的标准实现模板,包含服务定义、请求处理、错误处理和客户端调用。适用于需要高性能RPC通信的微服务架构。
327
+
328
+ ## 典型用法
329
+ ```python
330
+ # 服务端实现
331
+ import grpc
332
+ from concurrent import futures
333
+ import logging
334
+ import time
335
+ from typing import Dict, Any
336
+
337
+ import service_pb2
338
+ import service_pb2_grpc
339
+
340
+ class ServiceImplementation(service_pb2_grpc.MyServiceServicer):
341
+ def __init__(self, config: Dict[str, Any] = None):
342
+ self.config = config or {}
343
+ logging.info("RPC服务初始化完成")
344
+
345
+ def ProcessRequest(self, request, context):
346
+ try:
347
+ # 业务逻辑处理
348
+ result = self._process_business_logic(request)
349
+
350
+ # 构建响应
351
+ return service_pb2.Response(
352
+ status=200,
353
+ message="处理成功",
354
+ data=result
355
+ )
356
+ except Exception as e:
357
+ logging.error(f"处理请求时发生错误: {str(e)}")
358
+ context.set_code(grpc.StatusCode.INTERNAL)
359
+ context.set_details(f"服务器内部错误: {str(e)}")
360
+ return service_pb2.Response(
361
+ status=500,
362
+ message=f"处理失败: {str(e)}",
363
+ data={}
364
+ )
365
+
366
+ def _process_business_logic(self, request):
367
+ # 实际业务逻辑处理
368
+ return {"result": request.param1 + request.param2}
369
+
370
+ def serve(port=50051, max_workers=10):
371
+ server = grpc.server(futures.ThreadPoolExecutor(max_workers=max_workers))
372
+ service_pb2_grpc.add_MyServiceServicer_to_server(
373
+ ServiceImplementation(), server
374
+ )
375
+ server.add_insecure_port(f'[::]:{port}')
376
+ server.start()
377
+ logging.info(f"服务已启动,监听端口: {port}")
378
+
379
+ try:
380
+ while True:
381
+ time.sleep(86400) # 一天
382
+ except KeyboardInterrupt:
383
+ server.stop(0)
384
+ logging.info("服务已停止")
385
+
386
+ if __name__ == '__main__':
387
+ logging.basicConfig(level=logging.INFO)
388
+ serve()
389
+ ```
390
+
391
+ ## 依赖说明
392
+ - 需要安装 grpcio>=1.44.0 和 grpcio-tools>=1.44.0
393
+ - 需要预先定义proto文件并生成对应Python代码:
394
+ ```bash
395
+ python -m grpc_tools.protoc -I./protos --python_out=. --grpc_python_out=. ./protos/service.proto
396
+ ```
397
+ - 示例proto文件结构:
398
+ ```protobuf
399
+ syntax = "proto3";
400
+
401
+ service MyService {
402
+ rpc ProcessRequest (Request) returns (Response) {}
403
+ }
404
+
405
+ message Request {
406
+ int32 param1 = 1;
407
+ int32 param2 = 2;
408
+ }
409
+
410
+ message Response {
411
+ int32 status = 1;
412
+ string message = 2;
413
+ map<string, string> data = 3;
414
+ }
415
+ ```
416
+
417
+ ## 学习来源
418
+ 从src/services/rpc_service.py模块中的Server类和RequestHandler实现提取
419
+ </markdown>
420
+
421
+ ## 索引文件更新说明
422
+
423
+ 除了生成规则文件外,请务必更新index.md索引文件,记录所有规则及其作用。如果 index.md 当前内容为空,请按如下格式创建:
424
+
425
+ <markdown>
426
+ # Rules索引
427
+
428
+ 本文档记录项目中所有可用的代码规则(rules)及其用途。
429
+
430
+ ## [规则文件路径]
431
+ [规则文件的主要功能和适用场景简述]
432
+ </markdown>
433
+
434
+ ## 评价标准
435
+ - 提取的功能点必须具备独立价值,能在其他项目中实际复用
436
+ - 代码示例必须完整、可执行,包含所有必要组件
437
+ - 文档结构清晰,遵循规定格式
438
+ - 依赖说明明确具体,便于用户快速配置环境
439
+ """
440
+
441
+ # 获取索引文件内容
442
+ index_file_content = self._get_index_file_content()
443
+
444
+ return {
445
+ "project_root": os.path.abspath(self.args.source_dir),
446
+ "index_file_content": index_file_content
447
+ }
448
+
449
+ def get_commit_changes(self, commit_id: str) -> Tuple[List[Tuple[str, List[str], Dict[str, Tuple[str, str]]]], Optional[str]]:
450
+ """
451
+ 直接从Git仓库获取指定commit的变更
452
+
453
+ Args:
454
+ commit_id: Git commit的ID
455
+
456
+ Returns:
457
+ List[Tuple[str, List[str], Dict[str, Tuple[str, str]]]]: 包含查询、URL和变更信息的列表
458
+ """
459
+ printer = Printer()
460
+ querie_with_urls_and_changes = []
461
+ try:
462
+ repo = git.Repo(self.args.source_dir)
463
+ commit = repo.commit(commit_id)
464
+ modified_files = []
465
+ changes = {}
466
+
467
+ # 检查是否是首次提交(没有父提交)
468
+ if not commit.parents:
469
+ # 首次提交,获取所有文件
470
+ for item in commit.tree.traverse():
471
+ if item.type == 'blob': # 只处理文件,不处理目录
472
+ file_path = item.path
473
+ modified_files.append(file_path)
474
+ # 首次提交前没有内容
475
+ before_content = None
476
+ # 获取提交后的内容
477
+ after_content = repo.git.show(
478
+ f"{commit.hexsha}:{file_path}")
479
+ changes[file_path] = (before_content, after_content)
480
+ else:
481
+ # 获取parent commit
482
+ parent = commit.parents[0]
483
+ # 获取变更的文件列表
484
+ for diff_item in parent.diff(commit):
485
+ file_path = diff_item.a_path if diff_item.a_path else diff_item.b_path
486
+ modified_files.append(file_path)
487
+
488
+ # 获取变更前内容
489
+ before_content = None
490
+ try:
491
+ if diff_item.a_blob:
492
+ before_content = repo.git.show(
493
+ f"{parent.hexsha}:{file_path}")
494
+ except git.exc.GitCommandError:
495
+ pass # 文件可能是新增的
496
+
497
+ # 获取变更后内容
498
+ after_content = None
499
+ try:
500
+ if diff_item.b_blob:
501
+ after_content = repo.git.show(
502
+ f"{commit.hexsha}:{file_path}")
503
+ except git.exc.GitCommandError:
504
+ pass # 文件可能被删除
505
+
506
+ changes[file_path] = (before_content, after_content)
507
+
508
+ # 使用commit消息作为查询内容
509
+ query = commit.message
510
+ querie_with_urls_and_changes.append(
511
+ (query, modified_files, changes))
512
+
513
+ except git.exc.GitCommandError as e:
514
+ printer.print_in_terminal(
515
+ "git_command_error", style="red", error=str(e))
516
+ except Exception as e:
517
+ printer.print_in_terminal(
518
+ "get_commit_changes_error", style="red", error=str(e))
519
+
520
+ return querie_with_urls_and_changes, None
521
+
522
+ def analyze_commit_changes(self, query: str, commit_id: str, conversations: List[Dict] = []) -> Optional[Generator[str, None, None]]:
523
+ """
524
+ 分析指定commit的代码变更
525
+
526
+ Args:
527
+ query: 用户的查询/要求
528
+ commit_id: 指定的commit ID
529
+ conversations: 之前的对话历史 (可选)
530
+
531
+ Returns:
532
+ Optional[Generator]: 分析结果生成器,如果出错则返回None
533
+ """
534
+ printer = Printer()
535
+
536
+ # 获取commit的变更信息
537
+ changes, _ = self.get_commit_changes(commit_id)
538
+
539
+ if not changes:
540
+ printer.print_in_terminal("no_commit_changes", style="red")
541
+ return None
542
+
543
+ # 调用LLM进行代码分析
544
+ try:
545
+ # 获取prompt内容
546
+ prompt_content = self.analyze_commit.prompt(
547
+ querie_with_urls_and_changes=changes,
548
+ new_query=query
549
+ )
550
+
551
+ # 准备对话历史
552
+ if conversations:
553
+ new_conversations = conversations[:-1]
554
+ else:
555
+ new_conversations = []
556
+ new_conversations.append(
557
+ {"role": "user", "content": prompt_content})
558
+
559
+ # 调用LLM
560
+ v = stream_chat_with_continue(
561
+ llm=self.llm,
562
+ conversations=new_conversations,
563
+ llm_config={},
564
+ args=self.args
565
+ )
566
+ return v
567
+ except Exception as e:
568
+ printer.print_in_terminal(
569
+ "commit_analysis_error", style="red", error=str(e))
570
+ return None
571
+
572
+ def _get_index_file_content(self) -> str:
573
+ """获取索引文件内容"""
574
+ index_file_path = os.path.join(os.path.abspath(
575
+ self.args.source_dir), ".autocoderrules", "index.md")
576
+ index_file_content = ""
577
+
578
+ try:
579
+ if os.path.exists(index_file_path):
580
+ with open(index_file_path, 'r', encoding='utf-8') as f:
581
+ index_file_content = f.read()
582
+ except Exception as e:
583
+ self.printer.print_str_in_terminal(
584
+ f"读取索引文件时出错: {str(e)}", style="yellow")
585
+
586
+ return index_file_content
587
+
588
+ def analyze(self, sources: SourceCodeList, query: str, conversations: List[Dict] = []) -> Optional[Generator[str, None, None]]:
589
+ """
590
+ 分析给定的模块文件,根据用户需求生成可复用功能点的总结。
591
+
592
+ Args:
593
+ sources: 包含模块路径和内容的 SourceCodeList 对象。
594
+ query: 用户的具体分析要求。
595
+ conversations: 之前的对话历史 (可选)。
596
+
597
+ Returns:
598
+ Optional[Generator]: LLM 返回的分析结果生成器,如果出错则返回 None。
599
+ """
600
+ if not sources or not sources.sources:
601
+ self.printer.print_str_in_terminal("没有提供有效的模块文件进行分析。", style="red")
602
+ return None
603
+
604
+ try:
605
+ # 准备 Prompt
606
+ prompt_content = self.analyze_modules.prompt(
607
+ sources=sources,
608
+ query=query
609
+ )
610
+
611
+ # 准备对话历史
612
+ # 如果提供了 conversations,我们假设最后一个是用户的原始查询,替换它
613
+ if conversations:
614
+ new_conversations = conversations[:-1]
615
+ else:
616
+ new_conversations = []
617
+ new_conversations.append(
618
+ {"role": "user", "content": prompt_content})
619
+
620
+ # 调用 LLM
621
+ v = stream_chat_with_continue(
622
+ llm=self.llm,
623
+ conversations=new_conversations,
624
+ llm_config={},
625
+ args=self.args
626
+ )
627
+ return v
628
+ except Exception as e:
629
+ self.printer.print_in_terminal(
630
+ "代码分析时出错", style="red", error=str(e))
631
+ return None
autocoder/auto_coder.py CHANGED
@@ -184,6 +184,14 @@ def main(input_args: Optional[List[str]] = None):
184
184
  f.write("\n/actions/")
185
185
  f.write("\n/output.txt")
186
186
 
187
+ # 生成 .autocoderignore 文件,采用 .gitignore 格式
188
+ autocoderignore_path = os.path.join(source_dir, ".autocoderignore")
189
+ autocoderignore_content = (
190
+ "target\n"
191
+ )
192
+ with open(autocoderignore_path, "w", encoding="utf-8") as f:
193
+ f.write(autocoderignore_content)
194
+
187
195
  print(
188
196
  f"""Successfully initialized auto-coder project in {os.path.abspath(args.source_dir)}."""
189
197
  )