refactor: 统一 Packet 通信协议 + 后端配置管理 + UI 清理
- 合并 server.py 到 core/__init__.py,使用统一 Packet 协议 - 后端管理配置持久化 (~/.trulymem/config.json) - 前端移除 ConfigService,通过 BackendClient 与后端通信 - 删除 UI 中冗余的 AI 推理逻辑 (chat_service, tool_service, message_handler) - 删除 core/tools 重复文件 (tool_executor, tool_limiter) - 提示词管理器支持用户自定义 (~/.trulyemem/system_prompt.md) - 启动入口优化配置路径逻辑 - 更新测试覆盖 (42 tests) - 更新文档
This commit is contained in:
@ -10,6 +10,9 @@ class PromptManager:
|
||||
_instance = None
|
||||
_cached_prompt = None
|
||||
|
||||
# 用户自定义提示词路径
|
||||
USER_PROMPT_PATH = Path.home() / ".trulymem" / "system_prompt.md"
|
||||
|
||||
def __new__(cls):
|
||||
"""单例模式,避免重复加载"""
|
||||
if cls._instance is None:
|
||||
@ -26,11 +29,19 @@ class PromptManager:
|
||||
if PromptManager._cached_prompt is not None:
|
||||
return PromptManager._cached_prompt
|
||||
|
||||
# 1. 优先使用用户自定义提示词
|
||||
if self.USER_PROMPT_PATH.exists():
|
||||
with open(self.USER_PROMPT_PATH, "r", encoding="utf-8") as f:
|
||||
PromptManager._cached_prompt = f.read()
|
||||
return PromptManager._cached_prompt
|
||||
|
||||
# 2. 使用打包的提示词
|
||||
prompt_file = self.prompts_dir / "system_prompt.md"
|
||||
if prompt_file.exists():
|
||||
with open(prompt_file, "r", encoding="utf-8") as f:
|
||||
PromptManager._cached_prompt = f.read()
|
||||
else:
|
||||
# 3. 使用内置默认提示词
|
||||
PromptManager._cached_prompt = self._build_default_prompt()
|
||||
|
||||
return PromptManager._cached_prompt
|
||||
@ -78,3 +89,9 @@ class PromptManager:
|
||||
- 如何使用工具
|
||||
|
||||
记住:灵活应对,保持自然对话体验。"""
|
||||
|
||||
@staticmethod
|
||||
def clear_cache():
|
||||
"""清除缓存,强制重新加载提示词"""
|
||||
PromptManager._cached_prompt = None
|
||||
PromptManager._instance = None
|
||||
Reference in New Issue
Block a user