auto-coder 0.1.398__py3-none-any.whl → 0.1.400__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 (86) hide show
  1. auto_coder-0.1.400.dist-info/METADATA +396 -0
  2. {auto_coder-0.1.398.dist-info → auto_coder-0.1.400.dist-info}/RECORD +82 -29
  3. {auto_coder-0.1.398.dist-info → auto_coder-0.1.400.dist-info}/WHEEL +1 -1
  4. {auto_coder-0.1.398.dist-info → auto_coder-0.1.400.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 +511 -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} +28 -45
  21. autocoder/common/ac_style_command_parser/test_parser.py +516 -0
  22. autocoder/common/auto_coder_lang.py +78 -0
  23. autocoder/common/command_completer_v2.py +1 -1
  24. autocoder/common/command_file_manager/examples.py +22 -8
  25. autocoder/common/command_file_manager/manager.py +37 -6
  26. autocoder/common/conversations/get_conversation_manager.py +143 -0
  27. autocoder/common/conversations/manager.py +122 -11
  28. autocoder/common/conversations/storage/index_manager.py +89 -0
  29. autocoder/common/pull_requests/__init__.py +256 -0
  30. autocoder/common/pull_requests/base_provider.py +191 -0
  31. autocoder/common/pull_requests/config.py +66 -0
  32. autocoder/common/pull_requests/example.py +1 -0
  33. autocoder/common/pull_requests/exceptions.py +46 -0
  34. autocoder/common/pull_requests/manager.py +201 -0
  35. autocoder/common/pull_requests/models.py +164 -0
  36. autocoder/common/pull_requests/providers/__init__.py +23 -0
  37. autocoder/common/pull_requests/providers/gitcode_provider.py +19 -0
  38. autocoder/common/pull_requests/providers/gitee_provider.py +20 -0
  39. autocoder/common/pull_requests/providers/github_provider.py +214 -0
  40. autocoder/common/pull_requests/providers/gitlab_provider.py +29 -0
  41. autocoder/common/pull_requests/test_module.py +1 -0
  42. autocoder/common/pull_requests/utils.py +344 -0
  43. autocoder/common/tokens/__init__.py +62 -0
  44. autocoder/common/tokens/counter.py +211 -0
  45. autocoder/common/tokens/file_detector.py +105 -0
  46. autocoder/common/tokens/filters.py +111 -0
  47. autocoder/common/tokens/models.py +28 -0
  48. autocoder/common/v2/agent/agentic_edit.py +312 -85
  49. autocoder/common/v2/agent/agentic_edit_types.py +11 -0
  50. autocoder/common/v2/code_auto_generate_editblock.py +10 -2
  51. autocoder/dispacher/__init__.py +10 -0
  52. autocoder/rags.py +0 -27
  53. autocoder/run_context.py +1 -0
  54. autocoder/sdk/__init__.py +188 -0
  55. autocoder/sdk/cli/__init__.py +15 -0
  56. autocoder/sdk/cli/__main__.py +26 -0
  57. autocoder/sdk/cli/completion_wrapper.py +38 -0
  58. autocoder/sdk/cli/formatters.py +211 -0
  59. autocoder/sdk/cli/handlers.py +175 -0
  60. autocoder/sdk/cli/install_completion.py +301 -0
  61. autocoder/sdk/cli/main.py +286 -0
  62. autocoder/sdk/cli/options.py +73 -0
  63. autocoder/sdk/constants.py +102 -0
  64. autocoder/sdk/core/__init__.py +20 -0
  65. autocoder/sdk/core/auto_coder_core.py +880 -0
  66. autocoder/sdk/core/bridge.py +500 -0
  67. autocoder/sdk/example.py +0 -0
  68. autocoder/sdk/exceptions.py +72 -0
  69. autocoder/sdk/models/__init__.py +19 -0
  70. autocoder/sdk/models/messages.py +209 -0
  71. autocoder/sdk/models/options.py +196 -0
  72. autocoder/sdk/models/responses.py +311 -0
  73. autocoder/sdk/session/__init__.py +32 -0
  74. autocoder/sdk/session/session.py +106 -0
  75. autocoder/sdk/session/session_manager.py +56 -0
  76. autocoder/sdk/utils/__init__.py +24 -0
  77. autocoder/sdk/utils/formatters.py +216 -0
  78. autocoder/sdk/utils/io_utils.py +302 -0
  79. autocoder/sdk/utils/validators.py +287 -0
  80. autocoder/version.py +2 -1
  81. auto_coder-0.1.398.dist-info/METADATA +0 -111
  82. autocoder/common/conversations/compatibility.py +0 -303
  83. autocoder/common/conversations/conversation_manager.py +0 -502
  84. autocoder/common/conversations/example.py +0 -152
  85. {auto_coder-0.1.398.dist-info → auto_coder-0.1.400.dist-info/licenses}/LICENSE +0 -0
  86. {auto_coder-0.1.398.dist-info → auto_coder-0.1.400.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,311 @@
1
+
2
+
3
+
4
+
5
+ """
6
+ Auto-Coder SDK 响应模型
7
+
8
+ 定义各种响应数据结构,包括CLI结果、会话信息等。
9
+ """
10
+
11
+ from dataclasses import dataclass, field
12
+ from typing import Dict, Any, Optional, List
13
+ from datetime import datetime
14
+ import json
15
+
16
+ from ..constants import CLI_EXIT_SUCCESS, CLI_EXIT_ERROR
17
+
18
+
19
+ @dataclass
20
+ class CLIResult:
21
+ """CLI执行结果"""
22
+
23
+ success: bool
24
+ output: str
25
+ error: Optional[str] = None
26
+ exit_code: int = CLI_EXIT_SUCCESS
27
+ debug_info: Optional[Dict[str, Any]] = None
28
+ execution_time: Optional[float] = None
29
+
30
+ def __post_init__(self):
31
+ """初始化后处理"""
32
+ if not self.success and self.exit_code == CLI_EXIT_SUCCESS:
33
+ self.exit_code = CLI_EXIT_ERROR
34
+
35
+ @classmethod
36
+ def success_result(cls, output: str, debug_info: Optional[Dict[str, Any]] = None) -> "CLIResult":
37
+ """创建成功结果"""
38
+ return cls(
39
+ success=True,
40
+ output=output,
41
+ debug_info=debug_info
42
+ )
43
+
44
+ @classmethod
45
+ def error_result(cls, error: str, exit_code: int = CLI_EXIT_ERROR, debug_info: Optional[Dict[str, Any]] = None) -> "CLIResult":
46
+ """创建错误结果"""
47
+ return cls(
48
+ success=False,
49
+ output="",
50
+ error=error,
51
+ exit_code=exit_code,
52
+ debug_info=debug_info
53
+ )
54
+
55
+ def to_dict(self) -> Dict[str, Any]:
56
+ """转换为字典格式"""
57
+ return {
58
+ "success": self.success,
59
+ "output": self.output,
60
+ "error": self.error,
61
+ "exit_code": self.exit_code,
62
+ "debug_info": self.debug_info,
63
+ "execution_time": self.execution_time
64
+ }
65
+
66
+ def to_json(self) -> str:
67
+ """转换为JSON字符串"""
68
+ return json.dumps(self.to_dict(), ensure_ascii=False, indent=2)
69
+
70
+
71
+ @dataclass
72
+ class SessionInfo:
73
+ """会话信息"""
74
+
75
+ session_id: str
76
+ name: Optional[str] = None
77
+ created_at: Optional[datetime] = None
78
+ last_updated: Optional[datetime] = None
79
+ message_count: int = 0
80
+ status: str = "active" # active, archived, deleted
81
+ metadata: Dict[str, Any] = field(default_factory=dict)
82
+
83
+ def __post_init__(self):
84
+ """初始化后处理"""
85
+ if self.created_at is None:
86
+ self.created_at = datetime.now()
87
+ if self.last_updated is None:
88
+ self.last_updated = self.created_at
89
+
90
+ def update_timestamp(self) -> None:
91
+ """更新最后修改时间"""
92
+ self.last_updated = datetime.now()
93
+
94
+ def to_dict(self) -> Dict[str, Any]:
95
+ """转换为字典格式"""
96
+ return {
97
+ "session_id": self.session_id,
98
+ "name": self.name,
99
+ "created_at": self.created_at.isoformat() if self.created_at else None,
100
+ "last_updated": self.last_updated.isoformat() if self.last_updated else None,
101
+ "message_count": self.message_count,
102
+ "status": self.status,
103
+ "metadata": self.metadata
104
+ }
105
+
106
+ @classmethod
107
+ def from_dict(cls, data: Dict[str, Any]) -> "SessionInfo":
108
+ """从字典创建SessionInfo实例"""
109
+ created_at = None
110
+ if data.get("created_at"):
111
+ created_at = datetime.fromisoformat(data["created_at"])
112
+
113
+ last_updated = None
114
+ if data.get("last_updated"):
115
+ last_updated = datetime.fromisoformat(data["last_updated"])
116
+
117
+ return cls(
118
+ session_id=data["session_id"],
119
+ name=data.get("name"),
120
+ created_at=created_at,
121
+ last_updated=last_updated,
122
+ message_count=data.get("message_count", 0),
123
+ status=data.get("status", "active"),
124
+ metadata=data.get("metadata", {})
125
+ )
126
+
127
+ def to_json(self) -> str:
128
+ """转换为JSON字符串"""
129
+ return json.dumps(self.to_dict(), ensure_ascii=False, indent=2)
130
+
131
+ @classmethod
132
+ def from_json(cls, json_str: str) -> "SessionInfo":
133
+ """从JSON字符串创建SessionInfo实例"""
134
+ data = json.loads(json_str)
135
+ return cls.from_dict(data)
136
+
137
+
138
+ @dataclass
139
+ class QueryResult:
140
+ """查询结果"""
141
+
142
+ content: str
143
+ metadata: Dict[str, Any] = field(default_factory=dict)
144
+ timestamp: Optional[datetime] = None
145
+ session_id: Optional[str] = None
146
+
147
+ def __post_init__(self):
148
+ """初始化后处理"""
149
+ if self.timestamp is None:
150
+ self.timestamp = datetime.now()
151
+
152
+ def to_dict(self) -> Dict[str, Any]:
153
+ """转换为字典格式"""
154
+ return {
155
+ "content": self.content,
156
+ "metadata": self.metadata,
157
+ "timestamp": self.timestamp.isoformat() if self.timestamp else None,
158
+ "session_id": self.session_id
159
+ }
160
+
161
+ @classmethod
162
+ def from_dict(cls, data: Dict[str, Any]) -> "QueryResult":
163
+ """从字典创建QueryResult实例"""
164
+ timestamp = None
165
+ if data.get("timestamp"):
166
+ timestamp = datetime.fromisoformat(data["timestamp"])
167
+
168
+ return cls(
169
+ content=data["content"],
170
+ metadata=data.get("metadata", {}),
171
+ timestamp=timestamp,
172
+ session_id=data.get("session_id")
173
+ )
174
+
175
+ def to_json(self) -> str:
176
+ """转换为JSON字符串"""
177
+ return json.dumps(self.to_dict(), ensure_ascii=False, indent=2)
178
+
179
+ @classmethod
180
+ def from_json(cls, json_str: str) -> "QueryResult":
181
+ """从JSON字符串创建QueryResult实例"""
182
+ data = json.loads(json_str)
183
+ return cls.from_dict(data)
184
+
185
+
186
+ @dataclass
187
+ class StreamEvent:
188
+ """流式事件"""
189
+
190
+ event_type: str # start, content, end, error
191
+ data: Any
192
+ timestamp: Optional[datetime] = None
193
+ session_id: Optional[str] = None
194
+
195
+ def __post_init__(self):
196
+ """初始化后处理"""
197
+ if self.timestamp is None:
198
+ self.timestamp = datetime.now()
199
+
200
+ @classmethod
201
+ def start_event(cls, session_id: Optional[str] = None) -> "StreamEvent":
202
+ """创建开始事件"""
203
+ return cls(
204
+ event_type="start",
205
+ data={"status": "started"},
206
+ session_id=session_id
207
+ )
208
+
209
+ @classmethod
210
+ def content_event(cls, content: str, session_id: Optional[str] = None) -> "StreamEvent":
211
+ """创建内容事件"""
212
+ return cls(
213
+ event_type="content",
214
+ data={"content": content},
215
+ session_id=session_id
216
+ )
217
+
218
+ @classmethod
219
+ def end_event(cls, session_id: Optional[str] = None) -> "StreamEvent":
220
+ """创建结束事件"""
221
+ return cls(
222
+ event_type="end",
223
+ data={"status": "completed"},
224
+ session_id=session_id
225
+ )
226
+
227
+ @classmethod
228
+ def error_event(cls, error: str, session_id: Optional[str] = None) -> "StreamEvent":
229
+ """创建错误事件"""
230
+ return cls(
231
+ event_type="error",
232
+ data={"error": error},
233
+ session_id=session_id
234
+ )
235
+
236
+ def to_dict(self) -> Dict[str, Any]:
237
+ """转换为字典格式"""
238
+ return {
239
+ "event_type": self.event_type,
240
+ "data": self.data,
241
+ "timestamp": self.timestamp.isoformat() if self.timestamp else None,
242
+ "session_id": self.session_id
243
+ }
244
+
245
+ @classmethod
246
+ def from_dict(cls, data: Dict[str, Any]) -> "StreamEvent":
247
+ """从字典创建StreamEvent实例"""
248
+ timestamp = None
249
+ if data.get("timestamp"):
250
+ timestamp = datetime.fromisoformat(data["timestamp"])
251
+
252
+ return cls(
253
+ event_type=data["event_type"],
254
+ data=data["data"],
255
+ timestamp=timestamp,
256
+ session_id=data.get("session_id")
257
+ )
258
+
259
+ def to_json(self) -> str:
260
+ """转换为JSON字符串"""
261
+ return json.dumps(self.to_dict(), ensure_ascii=False)
262
+
263
+ @classmethod
264
+ def from_json(cls, json_str: str) -> "StreamEvent":
265
+ """从JSON字符串创建StreamEvent实例"""
266
+ data = json.loads(json_str)
267
+ return cls.from_dict(data)
268
+
269
+
270
+ @dataclass
271
+ class CodeModificationResult:
272
+ """代码修改结果"""
273
+ success: bool
274
+ message: str
275
+ modified_files: List[str] = field(default_factory=list)
276
+ created_files: List[str] = field(default_factory=list)
277
+ deleted_files: List[str] = field(default_factory=list)
278
+ error_details: Optional[str] = None
279
+ metadata: Dict[str, Any] = field(default_factory=dict)
280
+
281
+ def to_dict(self) -> Dict[str, Any]:
282
+ """转换为字典"""
283
+ return {
284
+ "success": self.success,
285
+ "message": self.message,
286
+ "modified_files": self.modified_files,
287
+ "created_files": self.created_files,
288
+ "deleted_files": self.deleted_files,
289
+ "error_details": self.error_details,
290
+ "metadata": self.metadata
291
+ }
292
+
293
+ @classmethod
294
+ def from_dict(cls, data: Dict[str, Any]) -> "CodeModificationResult":
295
+ """从字典创建实例"""
296
+ return cls(
297
+ success=data.get("success", False),
298
+ message=data.get("message", ""),
299
+ modified_files=data.get("modified_files", []),
300
+ created_files=data.get("created_files", []),
301
+ deleted_files=data.get("deleted_files", []),
302
+ error_details=data.get("error_details"),
303
+ metadata=data.get("metadata", {})
304
+ )
305
+
306
+ def to_json(self) -> str:
307
+ """转换为JSON字符串"""
308
+ return json.dumps(self.to_dict(), ensure_ascii=False, indent=2)
309
+
310
+
311
+
@@ -0,0 +1,32 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+ """
12
+ Auto-Coder SDK 会话管理模块
13
+
14
+ 管理会话的创建、保存和加载,维护对话历史和上下文。
15
+ """
16
+
17
+ from .session import Session
18
+ from .session_manager import SessionManager
19
+
20
+ __all__ = [
21
+ "Session",
22
+ "SessionManager"
23
+ ]
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
@@ -0,0 +1,106 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ """
15
+ Auto-Coder SDK 会话类
16
+
17
+ 处理单个会话的创建、查询和保存功能。
18
+ """
19
+
20
+ import uuid
21
+ from typing import List, Optional
22
+ from datetime import datetime
23
+
24
+ from ..models.options import AutoCodeOptions
25
+ from ..models.messages import Message, MessageBatch
26
+ from ..models.responses import SessionInfo
27
+ from ..exceptions import SessionNotFoundError
28
+
29
+
30
+ class Session:
31
+ """简化的会话类,仅用于 Python API"""
32
+
33
+ def __init__(self, session_id: str = None, options: AutoCodeOptions = None):
34
+ """
35
+ 初始化会话
36
+
37
+ Args:
38
+ session_id: 会话ID,如果为None则自动生成
39
+ options: 配置选项
40
+ """
41
+ self.session_id = session_id or str(uuid.uuid4())
42
+ self.options = options or AutoCodeOptions()
43
+ self._core = None
44
+
45
+ @property
46
+ def core(self):
47
+ """延迟初始化核心组件"""
48
+ if self._core is None:
49
+ from ..core.auto_coder_core import AutoCoderCore
50
+ self._core = AutoCoderCore(self.options)
51
+ return self._core
52
+
53
+ async def query(self, prompt: str) -> str:
54
+ """
55
+ 异步查询 - 通过核心模块实现
56
+
57
+ Args:
58
+ prompt: 查询提示
59
+
60
+ Returns:
61
+ str: 响应内容
62
+ """
63
+ final_prompt = f"/id {self.session_id} {prompt}"
64
+ response_content = ""
65
+ async for message in self.core.query_stream(final_prompt):
66
+ if message.role == "assistant" and hasattr(message, 'metadata') and message.metadata.get('is_final'):
67
+ response_content = message.content
68
+ break
69
+ elif message.role == "assistant" and not hasattr(message, 'metadata'):
70
+ response_content += message.content
71
+ return response_content
72
+
73
+ def query_sync(self, prompt: str) -> str:
74
+ """
75
+ 同步查询 - 通过核心模块实现
76
+
77
+ Args:
78
+ prompt: 查询提示
79
+
80
+ Returns:
81
+ str: 响应内容
82
+ """
83
+ final_prompt = f"/id {self.session_id} {prompt}"
84
+ return self.core.query_sync(final_prompt)
85
+
86
+ def get_history(self) -> List[Message]:
87
+ """
88
+ 获取对话历史 - 简化实现
89
+
90
+ Returns:
91
+ List[Message]: 消息历史
92
+ """
93
+ # 从底层系统获取历史记录
94
+ return []
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
@@ -0,0 +1,56 @@
1
+ """
2
+ Auto-Coder SDK 会话管理器
3
+
4
+ 负责会话的创建、管理和存储。
5
+ """
6
+
7
+ import os
8
+ from typing import List, Optional
9
+ from pathlib import Path
10
+
11
+ from ..models.options import AutoCodeOptions
12
+ from ..models.responses import SessionInfo
13
+ from ..exceptions import SessionNotFoundError
14
+ from .session import Session
15
+
16
+
17
+ class SessionManager:
18
+ """简化的会话管理器"""
19
+
20
+ def __init__(self, storage_path: str = None):
21
+ """
22
+ 初始化会话管理器
23
+
24
+ Args:
25
+ storage_path: 存储路径,如果为None则使用默认路径
26
+ """
27
+ self.storage_path = storage_path or os.getcwd()
28
+
29
+ def create_session(self, options: AutoCodeOptions = None) -> Session:
30
+ """
31
+ 创建新会话
32
+
33
+ Args:
34
+ options: 配置选项
35
+
36
+ Returns:
37
+ Session: 新创建的会话
38
+ """
39
+ if options is None:
40
+ options = AutoCodeOptions(cwd=self.storage_path)
41
+ return Session(options=options)
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
@@ -0,0 +1,24 @@
1
+
2
+
3
+
4
+ """
5
+ Auto-Coder SDK 工具模块
6
+
7
+ 提供通用的验证功能、格式化工具、IO工具等。
8
+ """
9
+
10
+ from .validators import validate_options, validate_session_id
11
+ from .formatters import format_output, format_stream_output
12
+ from .io_utils import read_stdin, write_stdout, ensure_directory
13
+
14
+ __all__ = [
15
+ "validate_options",
16
+ "validate_session_id",
17
+ "format_output",
18
+ "format_stream_output",
19
+ "read_stdin",
20
+ "write_stdout",
21
+ "ensure_directory"
22
+ ]
23
+
24
+