auto-coder 0.1.398__py3-none-any.whl → 0.1.399__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 (66) hide show
  1. auto_coder-0.1.399.dist-info/METADATA +396 -0
  2. {auto_coder-0.1.398.dist-info → auto_coder-0.1.399.dist-info}/RECORD +62 -28
  3. {auto_coder-0.1.398.dist-info → auto_coder-0.1.399.dist-info}/WHEEL +1 -1
  4. {auto_coder-0.1.398.dist-info → auto_coder-0.1.399.dist-info}/entry_points.txt +2 -0
  5. autocoder/agent/base_agentic/base_agent.py +2 -2
  6. autocoder/agent/base_agentic/tools/replace_in_file_tool_resolver.py +1 -1
  7. autocoder/agent/entry_command_agent/__init__.py +29 -0
  8. autocoder/agent/entry_command_agent/auto_tool.py +61 -0
  9. autocoder/agent/entry_command_agent/chat.py +475 -0
  10. autocoder/agent/entry_command_agent/designer.py +53 -0
  11. autocoder/agent/entry_command_agent/generate_command.py +50 -0
  12. autocoder/agent/entry_command_agent/project_reader.py +58 -0
  13. autocoder/agent/entry_command_agent/voice2text.py +71 -0
  14. autocoder/auto_coder.py +23 -548
  15. autocoder/auto_coder_runner.py +510 -8
  16. autocoder/chat/rules_command.py +1 -1
  17. autocoder/chat_auto_coder.py +6 -1
  18. autocoder/common/ac_style_command_parser/__init__.py +15 -0
  19. autocoder/common/ac_style_command_parser/example.py +7 -0
  20. autocoder/{command_parser.py → common/ac_style_command_parser/parser.py} +1 -33
  21. autocoder/common/ac_style_command_parser/test_parser.py +516 -0
  22. autocoder/common/command_completer_v2.py +1 -1
  23. autocoder/common/command_file_manager/examples.py +22 -8
  24. autocoder/common/command_file_manager/manager.py +37 -6
  25. autocoder/common/conversations/get_conversation_manager.py +143 -0
  26. autocoder/common/conversations/manager.py +122 -11
  27. autocoder/common/conversations/storage/index_manager.py +89 -0
  28. autocoder/common/v2/agent/agentic_edit.py +131 -18
  29. autocoder/common/v2/agent/agentic_edit_types.py +10 -0
  30. autocoder/common/v2/code_auto_generate_editblock.py +10 -2
  31. autocoder/dispacher/__init__.py +10 -0
  32. autocoder/rags.py +0 -27
  33. autocoder/run_context.py +1 -0
  34. autocoder/sdk/__init__.py +188 -0
  35. autocoder/sdk/cli/__init__.py +15 -0
  36. autocoder/sdk/cli/__main__.py +26 -0
  37. autocoder/sdk/cli/completion_wrapper.py +38 -0
  38. autocoder/sdk/cli/formatters.py +211 -0
  39. autocoder/sdk/cli/handlers.py +174 -0
  40. autocoder/sdk/cli/install_completion.py +301 -0
  41. autocoder/sdk/cli/main.py +284 -0
  42. autocoder/sdk/cli/options.py +72 -0
  43. autocoder/sdk/constants.py +102 -0
  44. autocoder/sdk/core/__init__.py +20 -0
  45. autocoder/sdk/core/auto_coder_core.py +867 -0
  46. autocoder/sdk/core/bridge.py +497 -0
  47. autocoder/sdk/example.py +0 -0
  48. autocoder/sdk/exceptions.py +72 -0
  49. autocoder/sdk/models/__init__.py +19 -0
  50. autocoder/sdk/models/messages.py +209 -0
  51. autocoder/sdk/models/options.py +194 -0
  52. autocoder/sdk/models/responses.py +311 -0
  53. autocoder/sdk/session/__init__.py +32 -0
  54. autocoder/sdk/session/session.py +106 -0
  55. autocoder/sdk/session/session_manager.py +56 -0
  56. autocoder/sdk/utils/__init__.py +24 -0
  57. autocoder/sdk/utils/formatters.py +216 -0
  58. autocoder/sdk/utils/io_utils.py +302 -0
  59. autocoder/sdk/utils/validators.py +287 -0
  60. autocoder/version.py +2 -1
  61. auto_coder-0.1.398.dist-info/METADATA +0 -111
  62. autocoder/common/conversations/compatibility.py +0 -303
  63. autocoder/common/conversations/conversation_manager.py +0 -502
  64. autocoder/common/conversations/example.py +0 -152
  65. {auto_coder-0.1.398.dist-info → auto_coder-0.1.399.dist-info/licenses}/LICENSE +0 -0
  66. {auto_coder-0.1.398.dist-info → auto_coder-0.1.399.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,38 @@
1
+
2
+
3
+ #!/usr/bin/env python3
4
+ """
5
+ Auto-Coder CLI 自动补全包装器
6
+
7
+ 提供一个独立的补全脚本,不依赖于特定的 shell 环境
8
+ """
9
+
10
+ import sys
11
+ import os
12
+
13
+ def main():
14
+ """主函数,处理自动补全请求"""
15
+ try:
16
+ # 设置环境变量以启用 argcomplete
17
+ os.environ.setdefault('_ARGCOMPLETE_COMPLETE', 'complete')
18
+
19
+ # 导入并运行 CLI
20
+ from autocoder.sdk.cli.main import AutoCoderCLI
21
+
22
+ # 模拟 auto-coder.run 命令
23
+ sys.argv[0] = 'auto-coder.run'
24
+
25
+ # 解析参数(这会触发自动补全)
26
+ AutoCoderCLI.parse_args()
27
+
28
+ except SystemExit:
29
+ # argcomplete 会调用 sys.exit,这是正常的
30
+ pass
31
+ except Exception as e:
32
+ # 在补全过程中出现错误,静默处理
33
+ pass
34
+
35
+ if __name__ == '__main__':
36
+ main()
37
+
38
+
@@ -0,0 +1,211 @@
1
+ """
2
+ 输出格式化器模块
3
+
4
+ 提供不同格式的输出处理,支持文本、JSON和流式JSON格式。
5
+ """
6
+
7
+ import json
8
+ import asyncio
9
+ from typing import Any, Dict, AsyncIterator, Union, Optional
10
+
11
+
12
+ class OutputFormatter:
13
+ """输出格式化器,处理不同格式的输出。"""
14
+
15
+ def __init__(self, verbose: bool = False):
16
+ """
17
+ 初始化输出格式化器。
18
+
19
+ Args:
20
+ verbose: 是否输出详细信息
21
+ """
22
+ self.verbose = verbose
23
+
24
+ def format_text(self, content: Union[str, Dict[str, Any]]) -> str:
25
+ """
26
+ 格式化为文本输出。
27
+
28
+ Args:
29
+ content: 要格式化的内容,可以是字符串或字典
30
+
31
+ Returns:
32
+ 格式化后的文本
33
+ """
34
+ if isinstance(content, dict):
35
+ # 如果是字典,提取主要内容
36
+ if "content" in content:
37
+ result = content["content"]
38
+ else:
39
+ result = str(content)
40
+ else:
41
+ result = str(content)
42
+
43
+ if self.verbose:
44
+ # 在详细模式下添加调试信息
45
+ debug_info = self._get_debug_info(content)
46
+ if debug_info:
47
+ result += f"\n\n[DEBUG]\n{debug_info}"
48
+
49
+ return result
50
+
51
+ def format_json(self, content: Any) -> str:
52
+ """
53
+ 格式化为JSON输出。
54
+
55
+ Args:
56
+ content: 要格式化的内容
57
+
58
+ Returns:
59
+ JSON格式的字符串
60
+ """
61
+ # 确保内容可以被序列化为JSON
62
+ if isinstance(content, str):
63
+ try:
64
+ # 尝试解析为JSON
65
+ parsed = json.loads(content)
66
+ content = parsed
67
+ except json.JSONDecodeError:
68
+ # 如果不是有效的JSON,则包装为字典
69
+ content = {"content": content}
70
+
71
+ # 添加调试信息(如果启用详细模式)
72
+ if self.verbose and isinstance(content, dict):
73
+ content["debug"] = self._get_debug_info_dict(content)
74
+
75
+ return json.dumps(content, ensure_ascii=False, indent=2)
76
+
77
+ async def format_stream_json(self, stream: AsyncIterator[Any]) -> AsyncIterator[str]:
78
+ """
79
+ 格式化为流式JSON输出。
80
+
81
+ Args:
82
+ stream: 异步迭代器,提供流式内容
83
+
84
+ Yields:
85
+ JSON格式的字符串,每行一个JSON对象
86
+ """
87
+ async for item in stream:
88
+ # 处理不同类型的项
89
+ if isinstance(item, dict):
90
+ output = item
91
+ elif isinstance(item, str):
92
+ try:
93
+ output = json.loads(item)
94
+ except json.JSONDecodeError:
95
+ output = {"content": item, "type": "text"}
96
+ else:
97
+ output = {"content": str(item), "type": "text"}
98
+
99
+ # 添加调试信息(如果启用详细模式)
100
+ if self.verbose:
101
+ output["debug"] = self._get_debug_info_dict(output)
102
+
103
+ yield json.dumps(output, ensure_ascii=False)
104
+
105
+ def _get_debug_info(self, content: Any) -> str:
106
+ """
107
+ 获取调试信息的文本表示。
108
+
109
+ Args:
110
+ content: 内容对象
111
+
112
+ Returns:
113
+ 调试信息文本
114
+ """
115
+ debug_dict = self._get_debug_info_dict(content)
116
+ if debug_dict:
117
+ return json.dumps(debug_dict, ensure_ascii=False, indent=2)
118
+ return ""
119
+
120
+ def _get_debug_info_dict(self, content: Any) -> Dict[str, Any]:
121
+ """
122
+ 获取调试信息的字典表示。
123
+
124
+ Args:
125
+ content: 内容对象
126
+
127
+ Returns:
128
+ 调试信息字典
129
+ """
130
+ debug_info = {}
131
+
132
+ # 从内容中提取元数据
133
+ if isinstance(content, dict):
134
+ if "metadata" in content:
135
+ debug_info["metadata"] = content["metadata"]
136
+
137
+ # 提取令牌计数信息
138
+ if "tokens" in content:
139
+ debug_info["tokens"] = content["tokens"]
140
+ elif "metadata" in content and "tokens" in content["metadata"]:
141
+ debug_info["tokens"] = content["metadata"]["tokens"]
142
+
143
+ # 提取模型信息
144
+ if "model" in content:
145
+ debug_info["model"] = content["model"]
146
+ elif "metadata" in content and "model" in content["metadata"]:
147
+ debug_info["model"] = content["metadata"]["model"]
148
+
149
+ # 提取时间信息
150
+ if "timestamp" in content:
151
+ debug_info["timestamp"] = content["timestamp"]
152
+ elif "metadata" in content and "timestamp" in content["metadata"]:
153
+ debug_info["timestamp"] = content["metadata"]["timestamp"]
154
+
155
+ return debug_info
156
+
157
+
158
+ class InputFormatter:
159
+ """输入格式化器,处理不同格式的输入。"""
160
+
161
+ def format_text(self, content: str) -> str:
162
+ """
163
+ 格式化文本输入。
164
+
165
+ Args:
166
+ content: 输入文本
167
+
168
+ Returns:
169
+ 格式化后的文本
170
+ """
171
+ return content.strip()
172
+
173
+ def format_json(self, content: str) -> Dict[str, Any]:
174
+ """
175
+ 格式化JSON输入。
176
+
177
+ Args:
178
+ content: JSON格式的输入字符串
179
+
180
+ Returns:
181
+ 解析后的字典
182
+
183
+ Raises:
184
+ ValueError: 如果输入不是有效的JSON
185
+ """
186
+ try:
187
+ return json.loads(content)
188
+ except json.JSONDecodeError as e:
189
+ raise ValueError(f"无效的JSON输入: {str(e)}")
190
+
191
+ async def format_stream_json(self, content: str) -> AsyncIterator[Dict[str, Any]]:
192
+ """
193
+ 格式化流式JSON输入。
194
+
195
+ Args:
196
+ content: 包含多行JSON对象的字符串
197
+
198
+ Yields:
199
+ 解析后的字典
200
+
201
+ Raises:
202
+ ValueError: 如果某行不是有效的JSON
203
+ """
204
+ for line in content.strip().split("\n"):
205
+ if not line.strip():
206
+ continue
207
+
208
+ try:
209
+ yield json.loads(line)
210
+ except json.JSONDecodeError as e:
211
+ raise ValueError(f"无效的JSON行: {line}, 错误: {str(e)}")
@@ -0,0 +1,174 @@
1
+ """
2
+ 命令处理器模块
3
+
4
+ 提供统一的命令处理器,支持单次运行和会话复用功能。
5
+ """
6
+
7
+ import sys
8
+ import asyncio
9
+ from pathlib import Path
10
+ from typing import Optional, Dict, Any, List, Union
11
+
12
+ from ..core import AutoCoderCore
13
+ from ..models import AutoCodeOptions, Message
14
+ from ..exceptions import AutoCoderSDKError
15
+ from .options import CLIOptions, CLIResult
16
+ from .formatters import OutputFormatter, InputFormatter
17
+
18
+
19
+ class CommandHandler:
20
+ """命令处理器基类,提供通用功能。"""
21
+
22
+ def __init__(self, options: CLIOptions, cwd: Optional[str] = None):
23
+ """
24
+ 初始化命令处理器。
25
+
26
+ Args:
27
+ options: CLI选项
28
+ cwd: 当前工作目录,如果为None则使用系统当前目录
29
+ """
30
+ self.options = options
31
+ self.cwd = Path(cwd) if cwd else Path.cwd()
32
+ self.output_formatter = OutputFormatter(verbose=options.verbose)
33
+ self.input_formatter = InputFormatter()
34
+
35
+ def _create_core_options(self) -> AutoCodeOptions:
36
+ """
37
+ 创建核心选项。
38
+
39
+ Returns:
40
+ AutoCodeOptions实例
41
+ """
42
+ return AutoCodeOptions(
43
+ max_turns=self.options.max_turns,
44
+ system_prompt=self.options.system_prompt,
45
+ cwd=str(self.cwd),
46
+ allowed_tools=self.options.allowed_tools,
47
+ permission_mode=self.options.permission_mode,
48
+ output_format=self.options.output_format,
49
+ stream=self.options.output_format.startswith("stream"),
50
+ session_id=self.options.resume_session,
51
+ continue_session=self.options.continue_session,
52
+ model=self.options.model
53
+ )
54
+
55
+ def _get_prompt(self) -> str:
56
+ """
57
+ 获取提示内容,如果未提供则从stdin读取。
58
+
59
+ Returns:
60
+ 提示内容
61
+
62
+ Raises:
63
+ ValueError: 如果未提供提示且stdin为空
64
+ """
65
+ if self.options.prompt:
66
+ return self.options.prompt
67
+
68
+ # 从stdin读取
69
+ if not sys.stdin.isatty():
70
+ content = sys.stdin.read()
71
+ if not content.strip():
72
+ raise ValueError("未提供提示内容且标准输入为空")
73
+
74
+ # 根据输入格式处理
75
+ if self.options.input_format == "text":
76
+ return self.input_formatter.format_text(content)
77
+ elif self.options.input_format == "json":
78
+ result = self.input_formatter.format_json(content)
79
+ # 尝试提取提示内容
80
+ if isinstance(result, dict):
81
+ if "prompt" in result:
82
+ return result["prompt"]
83
+ elif "message" in result:
84
+ message = result["message"]
85
+ if isinstance(message, dict) and "content" in message:
86
+ return message["content"]
87
+ elif isinstance(message, str):
88
+ return message
89
+ return content # 如果无法提取,则返回原始内容
90
+ else:
91
+ # 对于流式输入,暂时只支持直接传递
92
+ return content
93
+ else:
94
+ raise ValueError("未提供提示内容且没有标准输入")
95
+
96
+
97
+ class PrintModeHandler(CommandHandler):
98
+ """统一的命令处理器,支持单次运行和会话复用。"""
99
+
100
+ def handle(self) -> CLIResult:
101
+ """
102
+ 处理命令,支持会话复用。
103
+
104
+ Returns:
105
+ 命令执行结果
106
+ """
107
+ try:
108
+ prompt = self._get_prompt()
109
+ core_options = self._create_core_options()
110
+ core = AutoCoderCore(core_options)
111
+
112
+ # 根据会话参数构建完整的 prompt
113
+ final_prompt = self._build_prompt_with_session_context(prompt)
114
+
115
+ # 根据输出格式选择不同的处理方式
116
+ if self.options.output_format == "stream-json":
117
+ # 流式JSON输出
118
+ result = asyncio.run(self._handle_stream(core, final_prompt))
119
+ else:
120
+ # 同步查询
121
+ response = core.query_sync(final_prompt)
122
+
123
+ # 格式化输出
124
+ if self.options.output_format == "json":
125
+ result = self.output_formatter.format_json(response)
126
+ else:
127
+ result = self.output_formatter.format_text(response)
128
+
129
+ return CLIResult(success=True, output=result)
130
+
131
+ except Exception as e:
132
+ return CLIResult(success=False, error=str(e))
133
+
134
+ def _build_prompt_with_session_context(self, prompt: str) -> str:
135
+ """
136
+ 根据会话参数构建完整的 prompt。
137
+
138
+ Args:
139
+ prompt: 原始提示内容
140
+
141
+ Returns:
142
+ str: 构建后的完整提示
143
+ """
144
+ if self.options.continue_session:
145
+ # 继续当前对话
146
+ return f"{prompt}" if prompt else ""
147
+ elif self.options.resume_session:
148
+ # 恢复特定会话
149
+ return f"/resume {self.options.resume_session} {prompt}" if prompt else f"/resume {self.options.resume_session}"
150
+ else:
151
+ # 创建新对话
152
+ return f"/new {prompt}"
153
+
154
+ async def _handle_stream(self, core: AutoCoderCore, prompt: str) -> str:
155
+ """
156
+ 处理流式输出。
157
+
158
+ Args:
159
+ core: AutoCoderCore实例
160
+ prompt: 提示内容
161
+
162
+ Returns:
163
+ 处理结果
164
+ """
165
+ result = []
166
+ async for message in core.query_stream(prompt):
167
+ formatted = await anext(self.output_formatter.format_stream_json([message]))
168
+ result.append(formatted)
169
+ # 实时输出到stdout
170
+ print(formatted, flush=True)
171
+
172
+ return "\n".join(result)
173
+
174
+