修复: 消息溯源P2切读确认完成 + 走查报告高优项
- P2 切读方案文档更新(确认批次B已上线) - query LIKE 通配符转义(project/idea/task/knowledge 4 repo) - dag.rs deep_merge null 覆盖全局配置 - dag.rs 通配 match 展开显式变体 - INDEX.md 补漏 10 个文档索引 - ARCHITECTURE.md 删除与新文档逐字重复 - coordinator.rs 加 #[deprecated] 编译守卫 - AiChat.vue 空值传播加 console.warn
This commit is contained in:
@@ -2,50 +2,18 @@
|
||||
|
||||
> 决策:2026-06-28 — 一次性切读 + 脚本迁移历史数据
|
||||
|
||||
## 现状
|
||||
## 现状(2026-06-28 代码核查)
|
||||
|
||||
- `ai_messages` 表 ✅ 已存在(V21 迁移)
|
||||
- `AiMessageRepo` ✅ CRUD 已实现
|
||||
- V21 已有一次性数据迁移(从 `ai_conversations.messages` JSON 读 → 写入 `ai_messages`)
|
||||
- **但当前读写路径仍走 `ai_conversations.messages` JSON 列**,`ai_messages` 表未启用
|
||||
**P2 切读已完成**。上一阶段「批次 B」已经实现了读写路径切换:
|
||||
|
||||
## 目标
|
||||
### ✅ 读路径
|
||||
`ai_conversation_switch` 已优先从 `ai_messages` 表加载(`list_by_conversation`),
|
||||
空时 fallback 旧 `messages` JSON 列。见 `conversation.rs:257-282`。
|
||||
|
||||
读/写消息完全切换到 `ai_messages` 表,删除 `ai_conversations.messages` JSON 列。
|
||||
### ✅ 写路径
|
||||
`save_conversation` 已走 `AiMessageRepo.replace_conversation`(`DELETE + INSERT` 事务原子),
|
||||
旧 messages JSON 列保留不写作备份。见 `conversation.rs` 中 `save_conversation` 实现。
|
||||
|
||||
## 涉及改动
|
||||
|
||||
### 1. 数据迁移(已有 V21,补充幂等脚本)
|
||||
|
||||
V21 迁移已有从 `ai_conversations.messages` → `ai_messages` 的逻辑。补充:
|
||||
- V21 已幂等(`INSERT OR IGNORE`),可重复跑
|
||||
- 补充校验:迁移后 `ai_messages` 行数 = 各对话 messages JSON 汇总行数
|
||||
|
||||
### 2. 切读 — 后端代码
|
||||
|
||||
| 模块 | 当前 | 改为 |
|
||||
|------|------|------|
|
||||
| `restore_from_messages` | 从 `rec.messages` JSON 反序列化 | 从 `ai_messages` 表按 `conversation_id` 查询 + seq 排序 |
|
||||
| `save_conversation` | 写 `rec.messages` JSON 列 | 写 `ai_messages` 表(insert_batch + delete_range) |
|
||||
| `ai_conversation_switch` | 返回 `rec.messages`(JSON 反序列化) | 返回 `AiMessageRepo.list_by_conversation()` |
|
||||
| `clear_context` | 读/写 messages JSON | 读写 ai_messages 表 |
|
||||
| `compress_context` | 同上 | 同上 |
|
||||
| `replace_last_active_user_content` | 同上 | 同上 |
|
||||
| messages 相关 IPC 查询 | 走 JSON 列 | 走 ai_messages 表 |
|
||||
|
||||
### 3. 清理
|
||||
|
||||
- `ai_conversations.messages` 列标记废弃(暂不删列,避免大表 ALTER 风险)
|
||||
### 剩余工作
|
||||
- `ai_conversations.messages` 列标记废弃(暂不删列)
|
||||
- 后续 V22 可选删除该列
|
||||
|
||||
### 4. 风险控制
|
||||
|
||||
- **双写保护**:切读后写入同时写 ai_messages 表 + messages JSON 列(双写期 1 周,可回退)
|
||||
- **回退方案**:撤切读 → 恢复从 messages JSON 列读
|
||||
|
||||
## 执行顺序
|
||||
|
||||
1. 实现切读:改 `restore_from_messages` / `save_conversation` / `switch_conversation` 等核心路径
|
||||
2. 运行 V21 迁移(幂等,补全遗留数据)
|
||||
3. 双写期观察(ai_messages 数据一致)
|
||||
4. 切读完成,标记 messages 列废弃
|
||||
|
||||
Reference in New Issue
Block a user