auto-coder 0.1.397__py3-none-any.whl → 0.1.398__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.397.dist-info → auto_coder-0.1.398.dist-info}/METADATA +2 -2
- {auto_coder-0.1.397.dist-info → auto_coder-0.1.398.dist-info}/RECORD +30 -11
- autocoder/auto_coder_rag.py +1 -0
- autocoder/chat_auto_coder.py +3 -0
- autocoder/common/conversations/__init__.py +84 -39
- autocoder/common/conversations/backup/__init__.py +14 -0
- autocoder/common/conversations/backup/backup_manager.py +564 -0
- autocoder/common/conversations/backup/restore_manager.py +546 -0
- autocoder/common/conversations/cache/__init__.py +16 -0
- autocoder/common/conversations/cache/base_cache.py +89 -0
- autocoder/common/conversations/cache/cache_manager.py +368 -0
- autocoder/common/conversations/cache/memory_cache.py +224 -0
- autocoder/common/conversations/config.py +195 -0
- autocoder/common/conversations/exceptions.py +72 -0
- autocoder/common/conversations/file_locker.py +145 -0
- autocoder/common/conversations/manager.py +917 -0
- autocoder/common/conversations/models.py +154 -0
- autocoder/common/conversations/search/__init__.py +15 -0
- autocoder/common/conversations/search/filter_manager.py +431 -0
- autocoder/common/conversations/search/text_searcher.py +366 -0
- autocoder/common/conversations/storage/__init__.py +16 -0
- autocoder/common/conversations/storage/base_storage.py +82 -0
- autocoder/common/conversations/storage/file_storage.py +267 -0
- autocoder/common/conversations/storage/index_manager.py +317 -0
- autocoder/rags.py +73 -23
- autocoder/version.py +1 -1
- {auto_coder-0.1.397.dist-info → auto_coder-0.1.398.dist-info}/LICENSE +0 -0
- {auto_coder-0.1.397.dist-info → auto_coder-0.1.398.dist-info}/WHEEL +0 -0
- {auto_coder-0.1.397.dist-info → auto_coder-0.1.398.dist-info}/entry_points.txt +0 -0
- {auto_coder-0.1.397.dist-info → auto_coder-0.1.398.dist-info}/top_level.txt +0 -0
autocoder/rags.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import json
|
|
3
|
-
import fcntl
|
|
4
3
|
import platform
|
|
5
4
|
import time
|
|
6
5
|
from typing import Dict, Optional, Any, List
|
|
@@ -8,6 +7,17 @@ from pathlib import Path
|
|
|
8
7
|
from contextlib import contextmanager
|
|
9
8
|
from datetime import datetime
|
|
10
9
|
|
|
10
|
+
# 跨平台文件锁导入
|
|
11
|
+
try:
|
|
12
|
+
import fcntl
|
|
13
|
+
except ImportError:
|
|
14
|
+
fcntl = None
|
|
15
|
+
|
|
16
|
+
try:
|
|
17
|
+
import msvcrt
|
|
18
|
+
except ImportError:
|
|
19
|
+
msvcrt = None
|
|
20
|
+
|
|
11
21
|
|
|
12
22
|
RAGS_JSON = os.path.expanduser("~/.auto-coder/keys/rags_config.json")
|
|
13
23
|
|
|
@@ -29,6 +39,7 @@ class RAGConfigManager:
|
|
|
29
39
|
def _file_lock(self, mode='r'):
|
|
30
40
|
"""
|
|
31
41
|
文件锁上下文管理器,确保并发安全
|
|
42
|
+
支持Unix (fcntl) 和 Windows (msvcrt) 系统
|
|
32
43
|
"""
|
|
33
44
|
# 确保文件存在
|
|
34
45
|
if not os.path.exists(self.config_path):
|
|
@@ -36,36 +47,75 @@ class RAGConfigManager:
|
|
|
36
47
|
json.dump({}, f)
|
|
37
48
|
|
|
38
49
|
file_handle = open(self.config_path, mode)
|
|
50
|
+
lock_acquired = False
|
|
51
|
+
|
|
39
52
|
try:
|
|
53
|
+
# 尝试获取文件锁
|
|
40
54
|
if platform.system() != "Windows":
|
|
41
55
|
# Unix系统使用fcntl
|
|
42
|
-
if
|
|
43
|
-
fcntl.flock(file_handle.fileno(), fcntl.LOCK_EX) # 独占锁
|
|
44
|
-
else:
|
|
45
|
-
fcntl.flock(file_handle.fileno(), fcntl.LOCK_SH) # 共享锁
|
|
46
|
-
else:
|
|
47
|
-
# Windows系统的文件锁实现
|
|
48
|
-
try:
|
|
49
|
-
import msvcrt
|
|
56
|
+
if fcntl is not None:
|
|
50
57
|
if 'w' in mode or 'a' in mode or '+' in mode:
|
|
51
|
-
|
|
58
|
+
fcntl.flock(file_handle.fileno(), fcntl.LOCK_EX) # 独占锁
|
|
52
59
|
else:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
fcntl.flock(file_handle.fileno(), fcntl.LOCK_SH) # 共享锁
|
|
61
|
+
lock_acquired = True
|
|
62
|
+
else:
|
|
63
|
+
# Windows系统的文件锁实现
|
|
64
|
+
if msvcrt is not None:
|
|
65
|
+
try:
|
|
66
|
+
# 在Windows上,我们使用独占锁来简化实现
|
|
67
|
+
# msvcrt.locking 参数: fd, mode, nbytes
|
|
68
|
+
# LK_NBLCK: 非阻塞独占锁
|
|
69
|
+
# LK_LOCK: 阻塞独占锁
|
|
70
|
+
max_attempts = 10
|
|
71
|
+
for attempt in range(max_attempts):
|
|
72
|
+
try:
|
|
73
|
+
# 尝试锁定文件的第一个字节
|
|
74
|
+
file_handle.seek(0)
|
|
75
|
+
msvcrt.locking(file_handle.fileno(), msvcrt.LK_NBLCK, 1)
|
|
76
|
+
lock_acquired = True
|
|
77
|
+
break
|
|
78
|
+
except IOError:
|
|
79
|
+
# 如果锁被占用,等待一小段时间后重试
|
|
80
|
+
if attempt < max_attempts - 1:
|
|
81
|
+
time.sleep(0.1)
|
|
82
|
+
else:
|
|
83
|
+
# 最后一次尝试使用阻塞锁
|
|
84
|
+
try:
|
|
85
|
+
file_handle.seek(0)
|
|
86
|
+
msvcrt.locking(file_handle.fileno(), msvcrt.LK_LOCK, 1)
|
|
87
|
+
lock_acquired = True
|
|
88
|
+
except IOError:
|
|
89
|
+
# 如果仍然失败,继续执行但不使用锁
|
|
90
|
+
pass
|
|
91
|
+
except Exception:
|
|
92
|
+
# 如果出现任何异常,继续执行但不使用锁
|
|
93
|
+
pass
|
|
57
94
|
|
|
95
|
+
# 重置文件位置到开始
|
|
96
|
+
file_handle.seek(0)
|
|
58
97
|
yield file_handle
|
|
98
|
+
|
|
59
99
|
finally:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
100
|
+
try:
|
|
101
|
+
# 释放文件锁
|
|
102
|
+
if lock_acquired:
|
|
103
|
+
if platform.system() != "Windows":
|
|
104
|
+
if fcntl is not None:
|
|
105
|
+
fcntl.flock(file_handle.fileno(), fcntl.LOCK_UN)
|
|
106
|
+
else:
|
|
107
|
+
if msvcrt is not None:
|
|
108
|
+
try:
|
|
109
|
+
file_handle.seek(0)
|
|
110
|
+
msvcrt.locking(file_handle.fileno(), msvcrt.LK_UNLCK, 1)
|
|
111
|
+
except IOError:
|
|
112
|
+
# 忽略解锁错误
|
|
113
|
+
pass
|
|
114
|
+
except Exception:
|
|
115
|
+
# 忽略释放锁时的错误
|
|
116
|
+
pass
|
|
117
|
+
finally:
|
|
118
|
+
file_handle.close()
|
|
69
119
|
|
|
70
120
|
def _load_config(self) -> Dict[str, Any]:
|
|
71
121
|
"""
|
autocoder/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.1.
|
|
1
|
+
__version__ = "0.1.398"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|