diff --git a/README.md b/README.md index f8abadd..2ddb886 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ *The More Human Choice.* - [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/) [![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey.svg)]() @@ -57,32 +56,95 @@ pip install -r requirements.txt python trulymem_entry.py ``` -### 配置 +### 首次使用(TUI 登录) -1. 按 **F2** 展开侧边栏 +首次运行时会检测数据库状态,引导你完成: + +1. **TUI 登录页面** — 如果是新部署或无迁移需求,直接设置账号密码 +2. **旧版自动迁移** — 如果检测到旧版 `~/.trulymem/config.json`,自动引导迁移为多用户模式 +3. **首个用户自动成为管理员** + +登录后进入聊天界面: + +1. 按 **F2** 展开右侧配置面板 2. 输入 **API Key**(支持 DeepSeek、OpenAI 等兼容 API) 3. 按 **Enter** 保存配置 4. 开始对话! +📌 **管理员** 可在右侧面板管理 Web 服务开关、修改 Web 登录凭据。 +📌 **普通用户** 只能配置 API Key 和模型参数。 + --- -### Web 可视化界面(可选) +### 多用户系统 -TrulyMEM 提供 Web 星图可视化界面,支持实时浏览知识图谱: +TrulyMEM 支持多用户隔离,每个用户拥有独立的配置和数据目录: + +``` +~/.trulymem/ +├── trulymem.db # 全局用户数据库 +├── .migrated # 旧版迁移标记 +├── admin/ +│ ├── config.json # 管理员配置 +│ └── admin_graph.db # 管理员知识图谱 +└── user2/ + ├── config.json # user2 配置 + └── user2_graph.db # user2 知识图谱 +``` + +- **首个注册用户自动成为管理员** +- 管理员可在 Web 设置页添加/删除用户 +- 普通用户无法看到用户管理区域 + +### Web 可视化界面 + +TUI 启动后,管理员可在右侧面板勾选「启用 Web 服务」自动启动,或手动运行: ```bash -# 启动 Web 服务 +# 手动启动 Web 服务 python web_api.py --port 4096 ``` 然后打开浏览器访问 `http://localhost:4096`。 -**登录配置:** -1. 复制 `web_config.example.json` 为 `web_config.json` -2. 设置登录密码(使用 SHA256)和 secret key -3. Web 服务会自动读取该配置 +**首次访问** → 自动跳转至设置页,创建管理员账号 → 跳转至星图可视化页面。 -默认端口 4096,可通过 `--port` 参数修改。 +**Web 功能:** +- 🌟 星图可视化浏览知识图谱 +- ⚙ 设置页:修改密码、管理用户(管理员专属) +- 🔒 会话认证,多用户安全隔离 + +--- + +## 打包构建 + +项目支持 PyInstaller 打包为单文件可执行文件: + +```bash +# Linux +bash build/build_linux.sh + +# macOS +bash build/build_macos.sh + +# Windows +build\build_windows.bat + +# AppImage(Linux 通用打包) +bash build/build_appimage.sh +``` + +构建产出在 `dist/` 目录: + +| 文件 | 用途 | +|------|------| +| `TrulyMEM` | TUI 主程序(含 Web 子进程启动能力) | +| `trulymem-web` | Web 服务独立二进制(TUI 启动子进程时自动使用) | + +### Web 启动优先级(TUI 内) +1. 同目录 `trulymem-web` 二进制(打包环境) +2. `sys._MEIPASS/web_api.py`(PyInstaller 数据文件回退) +3. `python3 web_api.py`(开发环境回退) --- @@ -128,4 +190,4 @@ python web_api.py --port 4096 - anzhitinglan — 测试资源支持 - 崔莉萍老师 — 理论指导 - Annie — 专业指导 -- 王梓沣、马悦华、隆梦婷 — 神经科学理论支持 \ No newline at end of file +- 王梓沣、马悦华、隆梦婷 — 神经科学理论支持 diff --git a/README_EN.md b/README_EN.md index 2e740bb..258c3ef 100644 --- a/README_EN.md +++ b/README_EN.md @@ -13,7 +13,6 @@ *The More Human Choice.* - [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/) [![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20Linux%20%7C%20macOS-lightgrey.svg)]() @@ -57,18 +56,49 @@ pip install -r requirements.txt python trulymem_entry.py ``` -### Configuration +### First Run (TUI Login) -1. Press **F2** to expand sidebar -2. Enter **API Key** (supports DeepSeek, OpenAI, etc.) +On first launch, TrulyMEM will guide you through: + +1. **TUI Login Screen** — Set up your username and password +2. **Auto Migration** — If old `~/.trulymem/config.json` is detected, guides you through multi-user migration +3. **First user becomes admin automatically** + +After login: + +1. Press **F2** to expand the right-side configuration panel +2. Enter your **API Key** (supports DeepSeek, OpenAI, etc.) 3. Press **Enter** to save 4. Start chatting! +📌 **Admin users** can manage Web service settings and Web login credentials in the side panel. +📌 **Regular users** can only configure API Key and model parameters. + --- -### Web Visualization (Optional) +### Multi-User System -TrulyMEM provides a Web star-map visualization interface for browsing the knowledge graph in real-time: +TrulyMEM supports isolated multi-user environments. Each user has their own config and database: + +``` +~/.trulymem/ +├── trulymem.db # Global user database +├── .migrated # Migration flag +├── admin/ +│ ├── config.json # Admin config +│ └── admin_graph.db # Admin knowledge graph +└── user2/ + ├── config.json # user2 config + └── user2_graph.db # user2 knowledge graph +``` + +- **First user becomes admin automatically** +- Admins can add/delete users on the Web settings page +- Regular users cannot see the user management section + +### Web Visualization Interface + +From TUI, admin users can enable Web service via the right-side panel checkbox, or start manually: ```bash # Start Web service @@ -77,12 +107,44 @@ python web_api.py --port 4096 Then open `http://localhost:4096` in your browser. -**Login Setup:** -1. Copy `web_config.example.json` to `web_config.json` -2. Set login password (using SHA256) and secret key -3. Web service will automatically read the config +**First visit** → Auto-redirect to setup page → Create admin account → Redirect to star map visualization. -Default port is 4096, change with `--port` flag. +**Web features:** +- 🌟 Star map visualization for browsing the knowledge graph +- ⚙ Settings page: change password, manage users (admin only) +- 🔒 Session-based authentication with multi-user isolation + +--- + +## Building + +TrulyMEM supports PyInstaller packaging into single-file executables: + +```bash +# Linux +bash build/build_linux.sh + +# macOS +bash build/build_macos.sh + +# Windows +build\build_windows.bat + +# AppImage (Linux universal) +bash build/build_appimage.sh +``` + +Build outputs in `dist/`: + +| File | Purpose | +|------|---------| +| `TrulyMEM` | TUI main program (can spawn Web subprocess) | +| `trulymem-web` | Web service standalone binary (auto-detected by TUI) | + +### Web binary priority (within TUI) +1. `trulymem-web` in same directory (packaged) +2. `sys._MEIPASS/web_api.py` (PyInstaller data fallback) +3. `python3 web_api.py` (development fallback) --- @@ -128,4 +190,4 @@ See [LICENSE](LICENSE) file for details. - anzhitinglan — Testing resource support - 崔莉萍老师 — Theoretical guidance - Annie — Professional guidance -- 王梓沣、马悦华、隆梦婷 — Neuroscience theory support \ No newline at end of file +- 王梓沣、马悦华、隆梦婷 — Neuroscience theory support