docs(wiki): 重构为模块化知识库 — 按模块组织而非按文档类型
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

问题: 旧 wiki 按文档类型组织(architecture/data-flows/file-map),
修复 Butler Router 需要读 4 个文件才能拼凑全貌。
且 SaaS Relay 主路径 vs 本地降级的优先级描述不准确。

重构为模块化结构,每个模块页自包含:
- 设计思想: 为什么这样设计
- 代码逻辑: 数据流 + 关键代码
- 关联模块: 依赖关系

新增模块页:
- routing.md: 客户端路由 (明确 SaaS Relay 是主路径,不是本地模式)
- chat.md: 聊天系统 (3种实现 + Token Pool 中转机制)
- butler.md: 管家模式 (路由/冷启动/痛点/双模式UI)
- memory.md: 记忆管道 (提取→FTS5→检索→注入)
- saas.md: SaaS平台 (认证/Token池/计费/Admin)
- middleware.md: 中间件链 (14层 + 优先级)
- hands-skills.md: Hands(9) + Skills(75)
- pipeline.md: Pipeline DSL

删除旧文件: architecture.md, data-flows.md, module-status.md, file-map.md
(内容已分布到对应模块页中)

添加 .gitignore 排除 Obsidian 工作区状态文件
This commit is contained in:
iven
2026-04-11 00:36:26 +08:00
parent 9772d6ec94
commit 36a1c87d87
18 changed files with 839 additions and 627 deletions

83
wiki/butler.md Normal file
View File

@@ -0,0 +1,83 @@
---
title: 管家模式
updated: 2026-04-11
status: active
tags: [module, butler, interaction]
---
# 管家模式 (Butler Mode)
> 从 [[index]] 导航。关联模块: [[chat]] [[middleware]] [[memory]]
## 设计思想
**核心问题: 非技术用户(如医院行政)不会写 prompt需要 AI 主动引导。**
设计决策:
1. **默认激活** — 所有聊天都经过 ButlerRouter不需要用户手动开启
2. **4 域关键词分类** — healthcare / data_report / policy / meeting自动增强 system prompt
3. **痛点积累** — 从对话中提取用户痛点,积累后生成方案建议
4. **双模式 UI** — simple(纯聊天,默认) / professional(完整功能),渐进式解锁
## 代码逻辑
### 数据流
```
用户消息
→ ButlerRouter 中间件 (middleware/butler_router.rs)
→ SemanticSkillRouter TF-IDF 匹配 75 个技能
→ 4 域关键词分类
→ 增强 system prompt (领域专用指令)
→ LLM 响应
→ PainAggregator 提取痛点
→ PainStorage (内存 Vec 热缓存 + SQLite 持久层)
→ 全局 PAIN_STORAGE 单例
→ SolutionGenerator
→ 基于痛点生成解决方案提案
```
### 冷启动 (新用户引导)
入口: `desktop/src/hooks/use-cold-start.ts`
```
idle → (检测新用户) → greeting_sent → waiting_response → completed
```
4 个阶段,自动检测用户是否需要引导,发送欢迎消息,等待响应后完成。
### UI 双模式
| 模式 | Store | 特点 |
|------|-------|------|
| simple (默认) | `uiModeStore.ts` | 纯聊天界面,隐藏高级功能 |
| professional | `uiModeStore.ts` | 完整功能面板 |
切换文件: `desktop/src/store/uiModeStore.ts`
简洁侧边栏: `desktop/src/components/SimpleSidebar.tsx`
管家面板: `desktop/src/components/ButlerPanel.tsx` (3 区: 洞察/方案/记忆)
## 关联模块
- [[middleware]] — ButlerRouter 是中间件链中的一层
- [[chat]] — 消息流经过管家路由增强
- [[memory]] — 痛点存储在 memory 子系统
- [[hands-skills]] — 语义路由使用 75 个技能的 TF-IDF
## 关键文件
| 文件 | 职责 |
|------|------|
| `crates/zclaw-runtime/src/middleware/butler_router.rs` | 管家路由器 (4域分类) |
| `crates/zclaw-kernel/src/intelligence/pain_storage.rs` | 痛点双写 (内存+SQLite) |
| `crates/zclaw-kernel/src/intelligence/solution_generator.rs` | 方案生成 |
| `desktop/src/hooks/use-cold-start.ts` | 冷启动 4 阶段 |
| `desktop/src/store/uiModeStore.ts` | 双模式切换 |
| `desktop/src/components/SimpleSidebar.tsx` | 简洁模式侧边栏 |
| `desktop/src/components/ButlerPanel.tsx` | 管家面板 (洞察/方案/记忆) |
## Tauri 命令
6 个 butler 专属命令 (已标注 @reserved):
`butler_get_pain_points`, `butler_get_solutions`, `butler_delegate_task`, 等