落地偏好库与文风库存盘及注册表,便于创作节点按绑定注入。

先定无检索的节点绑定模型,替代原先未实现的检索方案。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-24 00:58:19 +08:00
co-authored by Cursor
parent dd0a9e87d8
commit 126874b65e
15 changed files with 1667 additions and 44 deletions
+78 -44
View File
@@ -1,63 +1,97 @@
# 用户偏好 RAG 库(待定)
# 用户偏好库 / 文风库
> 状态:**未实现**。先记设计共识与未决项,尤其 RAG 插入点。
## 已对齐
### 写库(学习,不改游玩上下文)
> 状态:**节点绑定(无 RAG)**。偏好与文风分库;创作节点声明 `libraries` 后注入,库空跳过。
- 累计对话轮次 ≥ **10**(可在设置中改)后,尝试从最近对话**总结**用户偏好。
- 弹出**审核卡**:通过 / 编辑后通过 / 合并到已有 / 跳过。
- 通过后才写入全局偏好库;支持**去重**与**更新已有条目**。
- 「随机插一条」= 往库里记候选,**不**修改当前轮 prompt。
### 读库(仅创建期)
- 根据用户输入 **Boss 直聘式**召回匹配条目(卡片点选)。
- 选中结果收成**本局固定上下文**(`resident_context` / 叙事指南合并),不在游玩期动态插入。
## 两库
### 条目形状(草案)
- `id`, `title`, `kind`(style|taboo|tone|format|other)
- `keys[]`(检索用), `content`, `mount[]`, `always_on?`
- `source`(manual|learned), `status`(active|archived)
## 未决:RAG 怎么插
| 库 | 存盘 | 绑定节点 | 注入 |
当前仓库**无 embedding / 向量检索**。需先定插入架构,再写代码。
|----|------|----------|------|
| 选项 | 做法 | 优点 | 风险 |
|------|------|------|------|
| A. 关键词召回 | `keys` + 标题匹配用户输入 | 零依赖、快落地 | 召回弱 |
| B. 创建期 LLM 选条 | 把库摘要交给 design-flow 一步选 | 与现有编排一致 | token、不稳定 |
| C. 本地 embedding | 条目向量化 + 相似度 Top-K | 真 RAG | 新依赖、索引维护 |
| D. 混合 | always_on + 关键词粗筛 +(可选)embedding 精排 | 可渐进 | 实现稍复杂 |
| **文风库** `style-packs` | `~/.writing-agent/style-packs.json` | 叙事指南、叙事指南与故事推进 | 【文风库 · 可选用】 |
**读库插入落点(创建期)候选:**
| **偏好库** `preferences` | `~/.writing-agent/preferences.json` | 用户需求 | 【偏好库 · 可选用】 |
1. `设计.用户偏好.选用集` fragment → `refine` 合并进 `resident_context` / 叙事 `情境备用` / `绝对禁忌`
2. 仅 `resident_context[]`,不经过叙事指南
3. 新设计步「用户偏好」专产选用集
**写库触发落点候选:**
1. `session-manager` 回合末计数 + 调 summarize API
2. 独立 `PreferenceService` + `/api/preferences/*`
3. 审核 UI 挂在 `SessionView.preferenceReview`
## 读写
## 建议实现顺序(定好 RAG 后再做)
1. 库 store + 手写样例条目
2. 设置项 `preferenceReviewEveryTurns`(默认 10)
3. 读库:关键词召回 + Boss 卡片 + 选用集 tag
4. `refine` 合并选用集 → 固定上下文
5. 写库:轮次触发 + 总结 + 审核 + 去重写回
6. (可选)embedding RAG
## 相关现有基建
| 阶段 | 行为 |
|------|------|
| **库页** | 顶栏「库」:手写 CRUD + LLM 提取入库 |
| **创作节点** | design-step / 对话落盘按 `libraries` 注入目录;节点选用写入本局产物 |
| **开玩** | **不再**全量自动摊偏好;靠产物 `设计.用户需求` / `设计.叙事指南*` 挂载 |
| **游玩** | 每隔 N 回合采集偏好候选(设置项);收下写入全局偏好库 |
## 偏好条目形状
- `id`, `content`, `status`(active|archived), `createdAt`, `updatedAt`
## 文风包形状
- `id`, `name`, `content`, `samples?`, `status`, `createdAt`, `updatedAt`
## 设置
- `preferenceCollectEveryTurns`:采集间隔(默认 10;0=关)
- 设置页「用户偏好」:只留间隔;CRUD 在库页
## API
- `GET/POST /api/preferences`;`PUT/DELETE /api/preferences/:id`
- `POST /api/preferences/extract`
- `GET/POST /api/style-packs`;`PUT/DELETE /api/style-packs/:id`
- `POST /api/style-packs/extract`
- `POST /api/sessions/:id/preferences/review`
## 实现
- `src/libraries/registry.ts` — 库注册 + `formatBoundLibrariesForPrompt`
- `src/style-pack/` — 文风库
- `src/preference/` — 偏好库 + extract
- `skills/.../modules/user-requirements/` — 用户需求节点
- `web/libraries.html` — 库页
- 常驻:`src/skills/resident-context.ts`,`设计.worker集.resident_context`
- 投影排序:`context-order` inserts
- 叙事写法档:`设计.叙事指南` → `情境备用`
- 设置:`src/config/settings.ts`
- 无游玩期上下文注入需求(与 `context-assembly.md` 一致)