auto-coder 0.1.359__py3-none-any.whl → 0.1.361__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.
- {auto_coder-0.1.359.dist-info → auto_coder-0.1.361.dist-info}/METADATA +1 -1
- {auto_coder-0.1.359.dist-info → auto_coder-0.1.361.dist-info}/RECORD +22 -19
- autocoder/agent/auto_review_commit.py +5 -3
- autocoder/auto_coder.py +3 -3
- autocoder/common/code_auto_generate.py +23 -2
- autocoder/common/code_auto_generate_diff.py +28 -3
- autocoder/common/code_auto_generate_editblock.py +27 -3
- autocoder/common/code_auto_generate_strict_diff.py +28 -2
- autocoder/common/directory_cache/__init__.py +1 -0
- autocoder/common/directory_cache/cache.py +192 -0
- autocoder/common/directory_cache/test_cache.py +190 -0
- autocoder/common/file_monitor/monitor.py +1 -1
- autocoder/common/v2/agent/agentic_edit.py +45 -30
- autocoder/common/v2/code_auto_generate.py +85 -1
- autocoder/common/v2/code_auto_generate_diff.py +8 -6
- autocoder/common/v2/code_auto_generate_editblock.py +26 -3
- autocoder/common/v2/code_auto_generate_strict_diff.py +27 -4
- autocoder/version.py +1 -1
- {auto_coder-0.1.359.dist-info → auto_coder-0.1.361.dist-info}/LICENSE +0 -0
- {auto_coder-0.1.359.dist-info → auto_coder-0.1.361.dist-info}/WHEEL +0 -0
- {auto_coder-0.1.359.dist-info → auto_coder-0.1.361.dist-info}/entry_points.txt +0 -0
- {auto_coder-0.1.359.dist-info → auto_coder-0.1.361.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
import os
|
|
3
|
+
import tempfile
|
|
4
|
+
import shutil
|
|
5
|
+
import asyncio
|
|
6
|
+
from unittest.mock import patch, MagicMock
|
|
7
|
+
|
|
8
|
+
# 导入被测模块
|
|
9
|
+
from autocoder.common.directory_cache.cache import DirectoryCache
|
|
10
|
+
|
|
11
|
+
# 测试环境辅助函数
|
|
12
|
+
def create_test_environment(base_dir, structure):
|
|
13
|
+
"""创建测试所需的文件/目录结构"""
|
|
14
|
+
for path, content in structure.items():
|
|
15
|
+
full_path = os.path.join(base_dir, path)
|
|
16
|
+
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
|
17
|
+
with open(full_path, 'w', encoding='utf-8') as f:
|
|
18
|
+
f.write(content)
|
|
19
|
+
|
|
20
|
+
# Pytest Fixture: 临时目录
|
|
21
|
+
@pytest.fixture(scope="function")
|
|
22
|
+
def temp_test_dir():
|
|
23
|
+
"""提供一个临时的、测试后自动清理的目录"""
|
|
24
|
+
temp_dir = tempfile.mkdtemp()
|
|
25
|
+
print(f"创建测试临时目录: {temp_dir}")
|
|
26
|
+
yield temp_dir
|
|
27
|
+
print(f"清理测试临时目录: {temp_dir}")
|
|
28
|
+
shutil.rmtree(temp_dir)
|
|
29
|
+
|
|
30
|
+
# Pytest Fixture: 重置单例
|
|
31
|
+
@pytest.fixture(autouse=True)
|
|
32
|
+
def reset_singleton():
|
|
33
|
+
"""每次测试前重置DirectoryCache单例"""
|
|
34
|
+
DirectoryCache._instance = None
|
|
35
|
+
yield
|
|
36
|
+
DirectoryCache._instance = None
|
|
37
|
+
|
|
38
|
+
# Pytest Fixture: 文件监视器模拟
|
|
39
|
+
@pytest.fixture
|
|
40
|
+
def mock_file_monitor():
|
|
41
|
+
"""模拟文件监视器"""
|
|
42
|
+
mock_monitor = MagicMock()
|
|
43
|
+
mock_monitor.register = MagicMock()
|
|
44
|
+
mock_monitor.is_running = MagicMock(return_value=False)
|
|
45
|
+
mock_monitor.start = MagicMock()
|
|
46
|
+
|
|
47
|
+
with patch('autocoder.common.directory_cache.cache.get_file_monitor', return_value=mock_monitor):
|
|
48
|
+
yield mock_monitor
|
|
49
|
+
|
|
50
|
+
# --- 测试用例 ---
|
|
51
|
+
|
|
52
|
+
@pytest.mark.asyncio
|
|
53
|
+
async def test_initialization(temp_test_dir, mock_file_monitor):
|
|
54
|
+
"""测试DirectoryCache的初始化和单例模式"""
|
|
55
|
+
# 创建测试文件结构
|
|
56
|
+
create_test_environment(temp_test_dir, {
|
|
57
|
+
"file1.txt": "测试内容1",
|
|
58
|
+
"subdir/file2.txt": "测试内容2",
|
|
59
|
+
".gitignore": "*.ignored"
|
|
60
|
+
})
|
|
61
|
+
create_test_environment(temp_test_dir, {
|
|
62
|
+
"file3.ignored": "这个文件应该被忽略"
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
# 获取实例
|
|
66
|
+
cache = DirectoryCache.get_instance(temp_test_dir)
|
|
67
|
+
|
|
68
|
+
# 验证单例模式
|
|
69
|
+
assert DirectoryCache.get_instance() is cache
|
|
70
|
+
assert cache.root == os.path.abspath(temp_test_dir)
|
|
71
|
+
|
|
72
|
+
# 验证文件缓存构建
|
|
73
|
+
assert len(cache.files_set) == 3 # file1.txt, subdir/file2.txt, .gitignore
|
|
74
|
+
assert os.path.join(temp_test_dir, "file1.txt") in [os.path.normpath(f) for f in cache.files_set]
|
|
75
|
+
assert os.path.join(temp_test_dir, "subdir/file2.txt") in [os.path.normpath(f) for f in cache.files_set]
|
|
76
|
+
|
|
77
|
+
# 验证监视器注册
|
|
78
|
+
mock_file_monitor.register.assert_called_once()
|
|
79
|
+
mock_file_monitor.start.assert_called_once()
|
|
80
|
+
|
|
81
|
+
@pytest.mark.asyncio
|
|
82
|
+
async def test_query_all_files(temp_test_dir, mock_file_monitor):
|
|
83
|
+
"""测试查询所有文件"""
|
|
84
|
+
# 创建测试文件结构
|
|
85
|
+
create_test_environment(temp_test_dir, {
|
|
86
|
+
"file1.py": "def test(): pass",
|
|
87
|
+
"file2.txt": "text content",
|
|
88
|
+
"subdir/file3.py": "class Test: pass"
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
# 获取实例并查询所有文件
|
|
92
|
+
cache = DirectoryCache.get_instance(temp_test_dir)
|
|
93
|
+
result = await cache.query(["*"])
|
|
94
|
+
|
|
95
|
+
# 验证结果
|
|
96
|
+
assert len(result) == 3
|
|
97
|
+
assert sorted([os.path.basename(f) for f in result]) == ["file1.py", "file2.txt", "file3.py"]
|
|
98
|
+
|
|
99
|
+
@pytest.mark.asyncio
|
|
100
|
+
async def test_query_with_pattern(temp_test_dir, mock_file_monitor):
|
|
101
|
+
"""测试使用模式查询文件"""
|
|
102
|
+
# 创建测试文件结构
|
|
103
|
+
create_test_environment(temp_test_dir, {
|
|
104
|
+
"file1.py": "def test(): pass",
|
|
105
|
+
"file2.txt": "text content",
|
|
106
|
+
"subdir/file3.py": "class Test: pass",
|
|
107
|
+
"another.doc": "document"
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
# 获取实例
|
|
111
|
+
cache = DirectoryCache.get_instance(temp_test_dir)
|
|
112
|
+
|
|
113
|
+
# 测试不同的查询模式
|
|
114
|
+
py_files = await cache.query(["*.py"])
|
|
115
|
+
assert len(py_files) == 2
|
|
116
|
+
assert all(f.endswith('.py') for f in py_files)
|
|
117
|
+
|
|
118
|
+
txt_files = await cache.query(["*.txt"])
|
|
119
|
+
assert len(txt_files) == 1
|
|
120
|
+
assert txt_files[0].endswith('file2.txt')
|
|
121
|
+
|
|
122
|
+
# 测试多模式查询
|
|
123
|
+
mixed_files = await cache.query(["*.py", "*.txt"])
|
|
124
|
+
assert len(mixed_files) == 3
|
|
125
|
+
assert len([f for f in mixed_files if f.endswith('.py')]) == 2
|
|
126
|
+
assert len([f for f in mixed_files if f.endswith('.txt')]) == 1
|
|
127
|
+
|
|
128
|
+
@pytest.mark.asyncio
|
|
129
|
+
async def test_file_change_events(temp_test_dir, mock_file_monitor):
|
|
130
|
+
"""测试文件变更事件处理"""
|
|
131
|
+
from watchfiles import Change
|
|
132
|
+
|
|
133
|
+
# 创建测试文件结构
|
|
134
|
+
create_test_environment(temp_test_dir, {
|
|
135
|
+
"file1.txt": "初始内容"
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
# 获取实例
|
|
139
|
+
cache = DirectoryCache.get_instance(temp_test_dir)
|
|
140
|
+
|
|
141
|
+
# 初始状态
|
|
142
|
+
file_path = os.path.join(temp_test_dir, "file1.txt")
|
|
143
|
+
abs_file_path = os.path.abspath(file_path)
|
|
144
|
+
assert abs_file_path in cache.files_set
|
|
145
|
+
|
|
146
|
+
# 测试删除事件
|
|
147
|
+
await cache._on_change(Change.deleted, abs_file_path)
|
|
148
|
+
assert abs_file_path not in cache.files_set
|
|
149
|
+
|
|
150
|
+
# 测试添加事件
|
|
151
|
+
await cache._on_change(Change.added, abs_file_path)
|
|
152
|
+
assert abs_file_path in cache.files_set
|
|
153
|
+
|
|
154
|
+
# 测试修改事件 (不应改变集合)
|
|
155
|
+
initial_set_size = len(cache.files_set)
|
|
156
|
+
await cache._on_change(Change.modified, abs_file_path)
|
|
157
|
+
assert len(cache.files_set) == initial_set_size
|
|
158
|
+
assert abs_file_path in cache.files_set
|
|
159
|
+
|
|
160
|
+
# 测试新文件
|
|
161
|
+
new_file_path = os.path.join(temp_test_dir, "newfile.txt")
|
|
162
|
+
abs_new_file_path = os.path.abspath(new_file_path)
|
|
163
|
+
await cache._on_change(Change.added, abs_new_file_path)
|
|
164
|
+
assert abs_new_file_path in cache.files_set
|
|
165
|
+
|
|
166
|
+
@pytest.mark.asyncio
|
|
167
|
+
async def test_reinitialization_with_different_root(temp_test_dir, mock_file_monitor):
|
|
168
|
+
"""测试使用不同根目录重新初始化缓存"""
|
|
169
|
+
# 创建第一个测试目录
|
|
170
|
+
first_dir = os.path.join(temp_test_dir, "first")
|
|
171
|
+
os.makedirs(first_dir)
|
|
172
|
+
create_test_environment(first_dir, {"test.txt": "first directory"})
|
|
173
|
+
|
|
174
|
+
# 初始化缓存
|
|
175
|
+
cache1 = DirectoryCache.get_instance(first_dir)
|
|
176
|
+
assert cache1.root == os.path.abspath(first_dir)
|
|
177
|
+
|
|
178
|
+
# 创建第二个测试目录
|
|
179
|
+
second_dir = os.path.join(temp_test_dir, "second")
|
|
180
|
+
os.makedirs(second_dir)
|
|
181
|
+
create_test_environment(second_dir, {"other.txt": "second directory"})
|
|
182
|
+
|
|
183
|
+
# 使用新目录重新初始化
|
|
184
|
+
cache2 = DirectoryCache.get_instance(second_dir)
|
|
185
|
+
assert cache2.root == os.path.abspath(second_dir)
|
|
186
|
+
|
|
187
|
+
# 验证文件集合已更新
|
|
188
|
+
all_files = await cache2.query(["*"])
|
|
189
|
+
assert len(all_files) == 1
|
|
190
|
+
assert all_files[0].endswith('other.txt')
|
|
@@ -153,7 +153,7 @@ class FileMonitor:
|
|
|
153
153
|
"""
|
|
154
154
|
# 将单个模式转换为pathspec格式
|
|
155
155
|
# 使用GitWildMatchPattern,它支持.gitignore样式的通配符,功能最全面
|
|
156
|
-
return pathspec.PathSpec
|
|
156
|
+
return pathspec.PathSpec([pathspec.patterns.GitWildMatchPattern(pattern)])
|
|
157
157
|
|
|
158
158
|
def register(self, path: Union[str, Path], callback: Callable[[Change, str], None]):
|
|
159
159
|
"""
|
|
@@ -595,14 +595,36 @@ class AgenticEdit:
|
|
|
595
595
|
- If at any point a mermaid diagram would make your plan clearer to help the user quickly see the structure, you are encouraged to include a Mermaid code block in the response. (Note: if you use colors in your mermaid diagrams, be sure to use high contrast colors so the text is readable.)
|
|
596
596
|
- Finally once it seems like you've reached a good plan, ask the user to switch you back to ACT MODE to implement the solution.
|
|
597
597
|
|
|
598
|
+
{% if enable_active_context_in_generate %}
|
|
599
|
+
====
|
|
600
|
+
|
|
601
|
+
PROJECT PACKAGE CONTEXT
|
|
602
|
+
|
|
603
|
+
Each directory can contain a short **`active.md`** summary file located under the mirrored path inside
|
|
604
|
+
`{{ current_project }}/.auto-coder/active-context/`.
|
|
605
|
+
|
|
606
|
+
* **Purpose** – captures only the files that have **recently changed** in that directory. It is *not* a full listing.
|
|
607
|
+
* **Example** – for `{{ current_project }}/src/abc/bbc`, the summary is
|
|
608
|
+
`{{ current_project }}/.auto-coder/active-context/src/abc/bbc/active.md`.
|
|
609
|
+
|
|
610
|
+
**Reading a summary**
|
|
611
|
+
|
|
612
|
+
```xml
|
|
613
|
+
<read_file>
|
|
614
|
+
<path>.auto-coder/active-context/src/abc/bbc/active.md</path>
|
|
615
|
+
</read_file>
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
Use these summaries to quickly decide which files deserve a deeper look with tools like
|
|
619
|
+
`read_file`, `search_files`, or `list_code_definition_names`.
|
|
620
|
+
|
|
621
|
+
{% endif %}
|
|
598
622
|
====
|
|
599
623
|
|
|
600
624
|
CAPABILITIES
|
|
601
625
|
|
|
602
|
-
- You have access to tools that let you execute CLI commands on the user's computer, list files, view source code definitions, regex search
|
|
603
|
-
|
|
604
|
-
}, read and edit files, and ask follow-up questions. These tools help you effectively accomplish a wide range of tasks, such as writing code, making edits or improvements to existing files, understanding the current state of a project, performing system operations, and much more.
|
|
605
|
-
- When the user initially gives you a task, a recursive list of all filepaths in the current working directory ('${cwd.toPosix()}') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current working directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop.
|
|
626
|
+
- You have access to tools that let you execute CLI commands on the user's computer, list files, view source code definitions, regex search, read and edit files, and ask follow-up questions. These tools help you effectively accomplish a wide range of tasks, such as writing code, making edits or improvements to existing files, understanding the current state of a project, performing system operations, and much more.
|
|
627
|
+
- When the user initially gives you a task, a recursive list of all filepaths in the current working directory ('{{ current_project }}') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current working directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop.
|
|
606
628
|
- You can use search_files to perform regex searches across files in a specified directory, outputting context-rich results that include surrounding lines. This is particularly useful for understanding code patterns, finding specific implementations, or identifying areas that need refactoring.
|
|
607
629
|
- You can use the list_code_definition_names tool to get an overview of source code definitions for all files at the top level of a specified directory. This can be particularly useful when you need to understand the broader context and relationships between certain parts of the code. You may need to call this tool multiple times to understand various parts of the codebase related to the task.
|
|
608
630
|
- For example, when asked to make edits or improvements you might analyze the file structure in the initial environment_details to get an overview of the project, then use list_code_definition_names to get further insight using source code definitions for files located in relevant directories, then read_file to examine the contents of relevant files, analyze the code and suggest improvements or make necessary edits, then use the replace_in_file tool to implement changes. If you refactored code that could affect other parts of the codebase, you could use search_files to ensure you update other files as needed.
|
|
@@ -613,7 +635,7 @@ class AgenticEdit:
|
|
|
613
635
|
RULES
|
|
614
636
|
|
|
615
637
|
- Your current working directory is: {{current_project}}
|
|
616
|
-
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '
|
|
638
|
+
- You cannot \`cd\` into a different directory to complete a task. You are stuck operating from '{{ current_project }}', so be sure to pass in the correct 'path' parameter when using tools that require a path.
|
|
617
639
|
- Do not use the ~ character or $HOME to refer to the home directory.
|
|
618
640
|
- Before using the execute_command tool, you must first think about the SYSTEM INFORMATION context provided to understand the user's environment and tailor your commands to ensure they are compatible with their system. You must also consider if the command you need to run should be executed in a specific directory outside of the current working directory '${cwd.toPosix()}', and if so prepend with \`cd\`'ing into that directory && then executing the command (as one command since you are stuck operating from '${cwd.toPosix()}'). For example, if you needed to run \`npm install\` in a project outside of '${cwd.toPosix()}', you would need to prepend with a \`cd\` i.e. pseudocode for this would be \`cd (path to project) && (command, in this case npm install)\`.
|
|
619
641
|
- When using the search_files tool, craft your regex patterns carefully to balance specificity and flexibility. Based on the user's task you may use it to find code patterns, TODO comments, function definitions, or any text-based information across the project. The results include context, so analyze the surrounding code to better understand the matches. Leverage the search_files tool in combination with other tools for more comprehensive analysis. For example, use it to find specific code patterns, then use read_file to examine the full context of interesting matches before using replace_in_file to make informed changes.
|
|
@@ -634,6 +656,21 @@ class AgenticEdit:
|
|
|
634
656
|
- When using the replace_in_file tool, you must include complete lines in your SEARCH blocks, not partial lines. The system requires exact line matches and cannot match partial lines. For example, if you want to match a line containing "const x = 5;", your SEARCH block must include the entire line, not just "x = 5" or other fragments.
|
|
635
657
|
- When using the replace_in_file tool, if you use multiple SEARCH/REPLACE blocks, list them in the order they appear in the file. For example if you need to make changes to both line 10 and line 50, first include the SEARCH/REPLACE block for line 10, followed by the SEARCH/REPLACE block for line 50.
|
|
636
658
|
- It is critical you wait for the user's response after each tool use, in order to confirm the success of the tool use. For example, if asked to make a todo app, you would create a file, wait for the user's response it was created successfully, then create another file if needed, wait for the user's response it was created successfully, etc.
|
|
659
|
+
|
|
660
|
+
{% if extra_docs %}
|
|
661
|
+
====
|
|
662
|
+
|
|
663
|
+
RULES PROVIDED BY USER
|
|
664
|
+
|
|
665
|
+
The following rules are provided by the user, and you must follow them strictly.
|
|
666
|
+
|
|
667
|
+
{% for key, value in extra_docs.items() %}
|
|
668
|
+
<user_rule>
|
|
669
|
+
##File: {{ key }}
|
|
670
|
+
{{ value }}
|
|
671
|
+
</user_rule>
|
|
672
|
+
{% endfor %}
|
|
673
|
+
{% endif %}
|
|
637
674
|
|
|
638
675
|
====
|
|
639
676
|
|
|
@@ -654,29 +691,7 @@ class AgenticEdit:
|
|
|
654
691
|
2. Work through these goals sequentially, utilizing available tools one at a time as necessary. Each goal should correspond to a distinct step in your problem-solving process. You will be informed on the work completed and what's remaining as you go.
|
|
655
692
|
3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within <thinking></thinking> tags. First, analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Then, think about which of the provided tools is the most relevant tool to accomplish the user's task. Next, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use. BUT, if one of the values for a required parameter is missing, DO NOT invoke the tool (not even with fillers for the missing params) and instead, ask the user to provide the missing parameters using the ask_followup_question tool. DO NOT ask for more information on optional parameters if it is not provided.
|
|
656
693
|
4. Once you've completed the user's task, you must use the attempt_completion tool to present the result of the task to the user. You may also provide a CLI command to showcase the result of your task; this can be particularly useful for web development tasks, where you can run e.g. \`open index.html\` to show the website you've built.
|
|
657
|
-
5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.
|
|
658
|
-
|
|
659
|
-
{% if enable_active_context %}
|
|
660
|
-
**Very Important Notice**
|
|
661
|
-
Each directory has a description file stored separately. For example, the description for the directory `{{ current_project }}/src/abc/bbc` can be found in the file `{{ current_project }}/.auto-coder/active-context/src/abc/bbc/active.md`.
|
|
662
|
-
You can use the tool `read_file` to read these description files, which helps you decide exactly which files need detailed attention. Note that the `active.md` file does not contain information about all files within the directory—it only includes information
|
|
663
|
-
about the files that were recently changed.
|
|
664
|
-
{% endif %}
|
|
665
|
-
|
|
666
|
-
{% if extra_docs %}
|
|
667
|
-
====
|
|
668
|
-
|
|
669
|
-
RULES PROVIDED BY USER
|
|
670
|
-
|
|
671
|
-
The following rules are provided by the user, and you must follow them strictly.
|
|
672
|
-
|
|
673
|
-
{% for key, value in extra_docs.items() %}
|
|
674
|
-
<user_rule>
|
|
675
|
-
##File: {{ key }}
|
|
676
|
-
{{ value }}
|
|
677
|
-
</user_rule>
|
|
678
|
-
{% endfor %}
|
|
679
|
-
{% endif %}
|
|
694
|
+
5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.
|
|
680
695
|
"""
|
|
681
696
|
import os
|
|
682
697
|
extra_docs = get_rules()
|
|
@@ -699,7 +714,7 @@ class AgenticEdit:
|
|
|
699
714
|
"home_dir": os.path.expanduser("~"),
|
|
700
715
|
"files": self.files.to_str(),
|
|
701
716
|
"mcp_server_info": self.mcp_server_info,
|
|
702
|
-
"
|
|
717
|
+
"enable_active_context_in_generate": self.args.enable_active_context_in_generate,
|
|
703
718
|
"extra_docs": extra_docs,
|
|
704
719
|
}
|
|
705
720
|
|
|
@@ -762,7 +777,7 @@ class AgenticEdit:
|
|
|
762
777
|
logger.info("Adding initial files context to conversation")
|
|
763
778
|
conversations.append({
|
|
764
779
|
"role":"user","content":f'''
|
|
765
|
-
|
|
780
|
+
The following are context files that the user is currently focusing on. These files are presented with their complete paths and up-to-date content, providing essential context to help you better understand the user's needs. If you need more detailed information about specific files or directories not shown here, you can use tools like read_file, search_files, or list_files to explore the codebase further.
|
|
766
781
|
<files>
|
|
767
782
|
{self.files.to_str()}
|
|
768
783
|
</files>'''
|
|
@@ -16,6 +16,8 @@ from autocoder.utils import llms as llm_utils
|
|
|
16
16
|
from autocoder.common import SourceCodeList
|
|
17
17
|
from autocoder.memory.active_context_manager import ActiveContextManager
|
|
18
18
|
from loguru import logger
|
|
19
|
+
from autocoder.common.rulefiles.autocoderrules_utils import get_rules
|
|
20
|
+
from autocoder.run_context import get_run_context,RunMode
|
|
19
21
|
|
|
20
22
|
class CodeAutoGenerate:
|
|
21
23
|
def __init__(
|
|
@@ -36,6 +38,88 @@ class CodeAutoGenerate:
|
|
|
36
38
|
if not isinstance(self.llms, list):
|
|
37
39
|
self.llms = [self.llms]
|
|
38
40
|
|
|
41
|
+
@byzerllm.prompt(llm=lambda self: self.llm)
|
|
42
|
+
def single_round_instruction(
|
|
43
|
+
self, instruction: str, content: str, context: str = "", package_context: str = ""
|
|
44
|
+
) -> str:
|
|
45
|
+
"""
|
|
46
|
+
{%- if structure %}
|
|
47
|
+
====
|
|
48
|
+
{{ structure }}
|
|
49
|
+
{%- endif %}
|
|
50
|
+
|
|
51
|
+
{%- if content %}
|
|
52
|
+
====
|
|
53
|
+
下面是一些文件路径以及每个文件对应的源码:
|
|
54
|
+
|
|
55
|
+
{{ content }}
|
|
56
|
+
{%- endif %}
|
|
57
|
+
|
|
58
|
+
{%- if package_context %}
|
|
59
|
+
====
|
|
60
|
+
下面是上面文件的一些信息(包括最近的变更情况):
|
|
61
|
+
<package_context>
|
|
62
|
+
{{ package_context }}
|
|
63
|
+
</package_context>
|
|
64
|
+
{%- endif %}
|
|
65
|
+
|
|
66
|
+
{%- if context %}
|
|
67
|
+
====
|
|
68
|
+
{{ context }}
|
|
69
|
+
{%- endif %}
|
|
70
|
+
|
|
71
|
+
{%- if extra_docs %}
|
|
72
|
+
====
|
|
73
|
+
|
|
74
|
+
RULES PROVIDED BY USER
|
|
75
|
+
|
|
76
|
+
The following rules are provided by the user, and you must follow them strictly.
|
|
77
|
+
|
|
78
|
+
{% for key, value in extra_docs.items() %}
|
|
79
|
+
<user_rule>
|
|
80
|
+
##File: {{ key }}
|
|
81
|
+
{{ value }}
|
|
82
|
+
</user_rule>
|
|
83
|
+
{% endfor %}
|
|
84
|
+
{% endif %}
|
|
85
|
+
|
|
86
|
+
下面是用户的需求:
|
|
87
|
+
|
|
88
|
+
{{ instruction }}
|
|
89
|
+
|
|
90
|
+
如果你需要生成代码,你生成的代码要符合这个格式:
|
|
91
|
+
|
|
92
|
+
```{lang}
|
|
93
|
+
##File: {FILE_PATH}
|
|
94
|
+
{CODE}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
```{lang}
|
|
98
|
+
##File: {FILE_PATH}
|
|
99
|
+
{CODE}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
其中,{lang}是代码的语言,{CODE}是代码的内容, {FILE_PATH} 是文件的路径(请尽量使用绝对路径),他们都在代码块中,请严格按上面的格式进行内容生成。
|
|
103
|
+
|
|
104
|
+
请确保每份代码的完整性,而不要只生成修改部分。
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
if not self.args.include_project_structure:
|
|
108
|
+
return {
|
|
109
|
+
"structure": "",
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
extra_docs = get_rules()
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
"structure": (
|
|
116
|
+
self.action.pp.get_tree_like_directory_structure()
|
|
117
|
+
if self.action
|
|
118
|
+
else ""
|
|
119
|
+
),
|
|
120
|
+
"extra_docs": extra_docs,
|
|
121
|
+
}
|
|
122
|
+
|
|
39
123
|
def single_round_run(
|
|
40
124
|
self, query: str, source_code_list: SourceCodeList
|
|
41
125
|
) -> CodeGenerateResult:
|
|
@@ -116,7 +200,7 @@ class CodeAutoGenerate:
|
|
|
116
200
|
generate_mode="diff"
|
|
117
201
|
)
|
|
118
202
|
|
|
119
|
-
if not self.args.human_as_model:
|
|
203
|
+
if not self.args.human_as_model or get_run_context().mode == RunMode.WEB:
|
|
120
204
|
with ThreadPoolExecutor(max_workers=len(self.llms) * self.generate_times_same_model) as executor:
|
|
121
205
|
futures = []
|
|
122
206
|
count = 0
|
|
@@ -16,6 +16,7 @@ from autocoder.utils import llms as llm_utils
|
|
|
16
16
|
from autocoder.common import SourceCodeList
|
|
17
17
|
from autocoder.memory.active_context_manager import ActiveContextManager
|
|
18
18
|
from autocoder.common.rulefiles.autocoderrules_utils import get_rules
|
|
19
|
+
from autocoder.run_context import get_run_context,RunMode
|
|
19
20
|
|
|
20
21
|
class CodeAutoGenerateDiff:
|
|
21
22
|
def __init__(
|
|
@@ -155,22 +156,23 @@ class CodeAutoGenerateDiff:
|
|
|
155
156
|
```
|
|
156
157
|
|
|
157
158
|
现在让我们开始一个新的任务:
|
|
158
|
-
|
|
159
|
-
====
|
|
159
|
+
|
|
160
160
|
{%- if structure %}
|
|
161
|
+
====
|
|
161
162
|
{{ structure }}
|
|
162
163
|
{%- endif %}
|
|
163
164
|
|
|
164
|
-
|
|
165
|
+
|
|
165
166
|
{%- if content %}
|
|
167
|
+
====
|
|
166
168
|
下面是一些文件路径以及每个文件对应的源码:
|
|
167
169
|
<files>
|
|
168
170
|
{{ content }}
|
|
169
171
|
</files>
|
|
170
172
|
{%- endif %}
|
|
171
|
-
|
|
172
|
-
====
|
|
173
|
+
|
|
173
174
|
{%- if package_context %}
|
|
175
|
+
====
|
|
174
176
|
下面是上面文件的一些信息(包括最近的变更情况):
|
|
175
177
|
<package_context>
|
|
176
178
|
{{ package_context }}
|
|
@@ -300,7 +302,7 @@ class CodeAutoGenerateDiff:
|
|
|
300
302
|
generate_mode="diff"
|
|
301
303
|
)
|
|
302
304
|
|
|
303
|
-
if not self.args.human_as_model:
|
|
305
|
+
if not self.args.human_as_model or get_run_context().mode == RunMode.WEB:
|
|
304
306
|
with ThreadPoolExecutor(max_workers=len(self.llms) * self.generate_times_same_model) as executor:
|
|
305
307
|
futures = []
|
|
306
308
|
count = 0
|
|
@@ -15,7 +15,9 @@ from autocoder.rag.token_counter import count_tokens
|
|
|
15
15
|
from autocoder.utils import llms as llm_utils
|
|
16
16
|
from autocoder.common import SourceCodeList
|
|
17
17
|
from autocoder.memory.active_context_manager import ActiveContextManager
|
|
18
|
+
from autocoder.common.rulefiles.autocoderrules_utils import get_rules
|
|
18
19
|
from loguru import logger
|
|
20
|
+
from autocoder.run_context import get_run_context,RunMode
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
|
|
@@ -175,13 +177,15 @@ class CodeAutoGenerateEditBlock:
|
|
|
175
177
|
{%- endif %}
|
|
176
178
|
|
|
177
179
|
{%- if content %}
|
|
180
|
+
====
|
|
178
181
|
下面是一些文件路径以及每个文件对应的源码:
|
|
179
182
|
<files>
|
|
180
183
|
{{ content }}
|
|
181
184
|
</files>
|
|
182
185
|
{%- endif %}
|
|
183
|
-
|
|
186
|
+
|
|
184
187
|
{%- if package_context %}
|
|
188
|
+
====
|
|
185
189
|
下面是上面文件的一些信息(包括最近的变更情况):
|
|
186
190
|
<package_context>
|
|
187
191
|
{{ package_context }}
|
|
@@ -194,6 +198,22 @@ class CodeAutoGenerateEditBlock:
|
|
|
194
198
|
</extra_context>
|
|
195
199
|
{%- endif %}
|
|
196
200
|
|
|
201
|
+
{%- if extra_docs %}
|
|
202
|
+
====
|
|
203
|
+
|
|
204
|
+
RULES PROVIDED BY USER
|
|
205
|
+
|
|
206
|
+
The following rules are provided by the user, and you must follow them strictly.
|
|
207
|
+
|
|
208
|
+
{% for key, value in extra_docs.items() %}
|
|
209
|
+
<user_rule>
|
|
210
|
+
##File: {{ key }}
|
|
211
|
+
{{ value }}
|
|
212
|
+
</user_rule>
|
|
213
|
+
{% endfor %}
|
|
214
|
+
{% endif %}
|
|
215
|
+
|
|
216
|
+
====
|
|
197
217
|
下面是用户的需求:
|
|
198
218
|
|
|
199
219
|
{{ instruction }}
|
|
@@ -204,7 +224,9 @@ class CodeAutoGenerateEditBlock:
|
|
|
204
224
|
"structure": "",
|
|
205
225
|
"fence_0": self.fence_0,
|
|
206
226
|
"fence_1": self.fence_1,
|
|
207
|
-
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
extra_docs = get_rules()
|
|
208
230
|
|
|
209
231
|
return {
|
|
210
232
|
"structure": (
|
|
@@ -214,6 +236,7 @@ class CodeAutoGenerateEditBlock:
|
|
|
214
236
|
),
|
|
215
237
|
"fence_0": self.fence_0,
|
|
216
238
|
"fence_1": self.fence_1,
|
|
239
|
+
"extra_docs": extra_docs,
|
|
217
240
|
}
|
|
218
241
|
|
|
219
242
|
def single_round_run(
|
|
@@ -296,7 +319,7 @@ class CodeAutoGenerateEditBlock:
|
|
|
296
319
|
generate_mode="editblock"
|
|
297
320
|
)
|
|
298
321
|
|
|
299
|
-
if not self.args.human_as_model:
|
|
322
|
+
if not self.args.human_as_model or get_run_context().mode == RunMode.WEB:
|
|
300
323
|
with ThreadPoolExecutor(max_workers=len(self.llms) * self.generate_times_same_model) as executor:
|
|
301
324
|
futures = []
|
|
302
325
|
count = 0
|
|
@@ -16,6 +16,8 @@ from autocoder.utils import llms as llm_utils
|
|
|
16
16
|
from autocoder.common import SourceCodeList
|
|
17
17
|
from autocoder.privacy.model_filter import ModelPathFilter
|
|
18
18
|
from autocoder.memory.active_context_manager import ActiveContextManager
|
|
19
|
+
from autocoder.common.rulefiles.autocoderrules_utils import get_rule
|
|
20
|
+
from autocoder.run_context import get_run_context,RunMode
|
|
19
21
|
class CodeAutoGenerateStrictDiff:
|
|
20
22
|
def __init__(
|
|
21
23
|
self, llm: byzerllm.ByzerLLM, args: AutoCoderArgs, action=None
|
|
@@ -118,10 +120,12 @@ class CodeAutoGenerateStrictDiff:
|
|
|
118
120
|
现在让我们开始一个新的任务:
|
|
119
121
|
|
|
120
122
|
{%- if structure %}
|
|
123
|
+
====
|
|
121
124
|
{{ structure }}
|
|
122
125
|
{%- endif %}
|
|
123
126
|
|
|
124
127
|
{%- if content %}
|
|
128
|
+
====
|
|
125
129
|
下面是一些文件路径以及每个文件对应的源码:
|
|
126
130
|
<files>
|
|
127
131
|
{{ content }}
|
|
@@ -129,6 +133,7 @@ class CodeAutoGenerateStrictDiff:
|
|
|
129
133
|
{%- endif %}
|
|
130
134
|
|
|
131
135
|
{%- if package_context %}
|
|
136
|
+
====
|
|
132
137
|
下面是上面文件的一些信息(包括最近的变更情况):
|
|
133
138
|
<package_context>
|
|
134
139
|
{{ package_context }}
|
|
@@ -136,14 +141,29 @@ class CodeAutoGenerateStrictDiff:
|
|
|
136
141
|
{%- endif %}
|
|
137
142
|
|
|
138
143
|
{%- if context %}
|
|
144
|
+
====
|
|
139
145
|
<extra_context>
|
|
140
146
|
{{ context }}
|
|
141
147
|
</extra_context>
|
|
142
148
|
{%- endif %}
|
|
143
149
|
|
|
144
|
-
|
|
150
|
+
{%- if extra_docs %}
|
|
151
|
+
====
|
|
145
152
|
|
|
146
|
-
|
|
153
|
+
RULES PROVIDED BY USER
|
|
154
|
+
|
|
155
|
+
The following rules are provided by the user, and you must follow them strictly.
|
|
156
|
+
|
|
157
|
+
{% for key, value in extra_docs.items() %}
|
|
158
|
+
<user_rule>
|
|
159
|
+
##File: {{ key }}
|
|
160
|
+
{{ value }}
|
|
161
|
+
</user_rule>
|
|
162
|
+
{% endfor %}
|
|
163
|
+
{% endif %}
|
|
164
|
+
|
|
165
|
+
====
|
|
166
|
+
下面是用户的需求:
|
|
147
167
|
|
|
148
168
|
每次生成一个文件的diff,然后询问我是否继续,当我回复继续,继续生成下一个文件的diff。当没有后续任务时,请回复 "__完成__" 或者 "__EOF__"。
|
|
149
169
|
"""
|
|
@@ -152,13 +172,16 @@ class CodeAutoGenerateStrictDiff:
|
|
|
152
172
|
return {
|
|
153
173
|
"structure": "",
|
|
154
174
|
}
|
|
175
|
+
|
|
176
|
+
extra_docs = get_rules()
|
|
155
177
|
|
|
156
178
|
return {
|
|
157
179
|
"structure": (
|
|
158
180
|
self.action.pp.get_tree_like_directory_structure()
|
|
159
181
|
if self.action
|
|
160
182
|
else ""
|
|
161
|
-
)
|
|
183
|
+
),
|
|
184
|
+
"extra_docs": extra_docs,
|
|
162
185
|
}
|
|
163
186
|
|
|
164
187
|
@byzerllm.prompt(llm=lambda self: self.llm)
|
|
@@ -353,7 +376,7 @@ class CodeAutoGenerateStrictDiff:
|
|
|
353
376
|
generate_mode="strict_diff"
|
|
354
377
|
)
|
|
355
378
|
|
|
356
|
-
if not self.args.human_as_model:
|
|
379
|
+
if not self.args.human_as_model or get_run_context().mode == RunMode.WEB:
|
|
357
380
|
with ThreadPoolExecutor(max_workers=len(self.llms) * self.generate_times_same_model) as executor:
|
|
358
381
|
futures = []
|
|
359
382
|
count = 0
|
autocoder/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.1.
|
|
1
|
+
__version__ = "0.1.361"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|