complete: comprehensive tests and docs update

- 37 tests covering core, ui, and integration
- TestPacketType, Packet, BackendServer, BackendClient tests
- UI component imports and functionality tests
- Integration workflow tests
- Updated README.md with new architecture
- Updated docs/架构.md with packet protocol
This commit is contained in:
root
2026-04-12 20:54:07 +08:00
parent 5c76b19624
commit 178c45c410
8 changed files with 982 additions and 311 deletions

140
README.md
View File

@ -26,6 +26,7 @@ TrulyMEM (TrueHumanMEM) 是一个让 AI 拥有长期记忆能力的图记忆系
- 💾 **内嵌数据库** - SQLite 实现,无需 Docker/Neo4j
- 📦 **独立部署** - 支持打包为独立可执行文件
- 🌍 **跨平台** - 支持 Windows/Linux/macOS
- 🔌 **后端独立** - 后端可脱离 UI 独立运行
---
@ -60,6 +61,60 @@ python trulymem_entry.py
---
## 架构设计
### 核心原则
- **后端独立**: BackendServer 可脱离 UI 独立运行
- **数据包通信**: 所有通信使用 Packet 格式 `{id, type, body}`
- **多线程**: 后端在独立线程处理请求
- **UI 简化**: UI 仅负责输入和显示
### 数据包协议
```python
@dataclass
class Packet:
id: str # 包ID,用于识别
type: PacketType # MESSAGE | CONFIG | TOOL | STATUS | HISTORY
body: Dict # 包体
```
### 项目结构
```
TrulyMEM-TrueHumanMEM/
├── trulymem_entry.py # 入口
├── core/ # 后端(独立运行)
│ ├── __init__.py # BackendServer, BackendClient, Packet
│ ├── embedded_db.py # SQLite 图数据库
│ ├── graph_client.py # LLM 客户端
│ └── tools/ # 工具定义
├── ui/ # TUI 显示层
│ ├── app.py # 主应用
│ ├── widgets/ # UI 组件
│ └── models/ # 数据模型
└── tests/ # 测试 (37 tests)
```
### 启动流程
```python
# 1. 创建后端
server = BackendServer(db_path="graph_memory.db")
server.start(api_key="your-key")
# 2. 创建UI(可选,后端可独立使用)
app = GraphMemoryApp(backend_server=server)
app.run()
# 或直接使用后端
client = BackendClient(server)
result = client.send_message("hello")
```
---
## 功能说明
### 记忆管理工具
@ -96,38 +151,25 @@ python trulymem_entry.py
| F1 | 帮助 |
| F2 | 切换侧边栏 |
| F3 | 工具详情 |
| F4 | 聚焦查询框 |
| F5 | 清屏 |
| F6 | 退出 |
---
## 项目结构
## 测试
```bash
pytest tests/
```
TrulyMEM-TrueHumanMEM/
├── trulymem_entry.py # 入口:先启动 core → 再启动 ui
├── core/ # 后端/业务逻辑
│ ├── __init__.py
│ ├── server.py # BackendServer (多线程)
│ ├── client.py # BackendClient
│ ├── embedded_db.py # SQLite 图数据库
│ ├── graph_client.py
│ ├── tool_executor.py
│ ├── tool_limiter.py
│ ├── memory_tools.py
│ ├── prompts/
│ └── tools/ # TOOLS 定义
├── ui/ # TUI 显示层
│ ├── __init__.py
│ ├── app.py
│ ├── widgets/
│ ├── handlers/
│ ├── models/
│ ├── services/
│ └── styles/
└── tests/ # 测试 (38 tests)
```
37 个测试用例覆盖:
- 数据包协议
- 后端初始化/启动/关闭
- 客户端方法
- 配置管理
- 消息历史
- UI 组件
- 集成测试
---
@ -137,40 +179,8 @@ TrulyMEM-TrueHumanMEM/
- **Textual** - TUI 框架
- **SQLite** - 内嵌图数据库
- **OpenAI SDK** - API 调用(兼容 DeepSeek)
---
## 架构说明
### TUI 与后端通信
```
trulymem_entry.py
│
├─ 1. BackendServer.start() → 启动独立线程
│
├─ 2. GraphMemoryApp(backend_server=server)
│
└─ 3. BackendClient ← Queue → BackendServer
```
- **core/** - 业务逻辑(数据库、API调用、工具执行)
- **ui/** - 显示逻辑(Textual 组件)
- 多线程 Queue 通信解耦
---
## 开发指南
```bash
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
pip install -r requirements.txt
pytest tests/
```
- **threading** - 多线程通信
- **queue** - 线程安全队列
---
@ -196,14 +206,4 @@ pytest tests/
2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)
3. 提交更改 (`git commit -m 'Add some AmazingFeature'`)
4. 推送到分支 (`git push origin feature/AmazingFeature`)
5. 创建 Pull Request
---
## 文档
更多文档见 [docs/](docs/) 目录:
- [架构设计](docs/架构.md) - 系统架构和技术设计
- [快速开始](docs/一键启动指南.md) - 启动指南
- [工作记忆链机制说明](docs/工作记忆链机制说明.md) - 连续性任务处理
5. 创建 Pull Request