@cloud411716/fancy-webnovel 4.27.3 → 4.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/douyin-plugin.md +9 -1
- package/docs/material-library/README.md +53 -53
- package/docs/material-library/prompt.md +12 -6
- package/docs/material-library/schema.surql +40 -1
- package/docs/workspace-mcp.md +4 -3
- package/lib/material-db.js +9 -2
- package/package.json +1 -1
- package/plugins/fancy-bootstrap/index.js +1 -1
- package/plugins/fancy-db/index.js +1 -1
- package/plugins/fancy-douyin/index.js +80 -1
- package/plugins/fancy-douyin/state.js +24 -1
- package/plugins/fancy-douyin/style-distill.js +197 -0
- package/plugins/fancy-douyin/templates.js +8 -1
- package/plugins/fancy-material/builtin-styles.js +448 -0
- package/plugins/fancy-material/index.js +741 -190
- package/plugins/fancy-material/inventory.js +10 -8
- package/plugins/fancy-material/prompts/world-mother.md +81 -0
- package/plugins/fancy-material/styles.js +441 -0
- package/plugins/fancy-material/templates.js +56 -22
- package/plugins/fancy-material/world.js +602 -0
- package/plugins/fancy-topic/index.js +39 -18
- package/plugins/fancy-topic/prompts/02-setup-prompt.md +44 -25
- package/plugins/fancy-topic/scripts/save-minimal-topic.js +1 -1
- package/plugins/fancy-topic/templates.js +33 -19
package/docs/douyin-plugin.md
CHANGED
|
@@ -184,7 +184,15 @@ id / kind / subkind / name / tags / genres / note / source
|
|
|
184
184
|
|
|
185
185
|
## 任务状态与恢复
|
|
186
186
|
|
|
187
|
-
素材库 schema v12 新增 `douyin_account` 账号表;schema v11 新增多层素材 facet,并保留 `douyin_job` 和 `douyin_meta` 任务表。账号、任务状态与素材在同一个数据库里,备份/迁移整个素材库时会一起带走。
|
|
187
|
+
素材库 schema v13 新增 `douyin_style` 账号风格表;schema v12 新增 `douyin_account` 账号表;schema v11 新增多层素材 facet,并保留 `douyin_job` 和 `douyin_meta` 任务表。账号、任务状态与素材在同一个数据库里,备份/迁移整个素材库时会一起带走。
|
|
188
|
+
|
|
189
|
+
### 账号风格(douyin_style)
|
|
190
|
+
|
|
191
|
+
`douyin_style` 一个账号可以有多条记录(`style_key` 唯一),保存从作品提炼出的风格 DNA、命名规则、词汇域、跨 kind 示例、反例和题材兼容度。
|
|
192
|
+
|
|
193
|
+
- 每次采集结束、作品全部入库后,fancy-douyin 会按账号读取已有风格,用新作品做增量 patch,只写 `douyin_style`,不删除素材。
|
|
194
|
+
- `/fancy-douyin list` 会显示账号的 `style_key`、风格名、DNA 和示例,用户可直接把 key 传给 `/fancy-material --style <key>`。
|
|
195
|
+
- 内置风格在 `plugins/fancy-material/builtin-styles.js`;fancy-material 会把内置风格和数据库风格按 `style_key` 合并,数据库版本优先。
|
|
188
196
|
|
|
189
197
|
`/fancy-douyin add`、`list`、`remove` 现在直接读写 `douyin_account`。旧 `accounts.json` 只在首次运行时迁移一次,之后不再作为运行时状态源。
|
|
190
198
|
|
|
@@ -28,6 +28,10 @@ plugins/fancy-material/
|
|
|
28
28
|
├── exporter.js # 导出 Markdown
|
|
29
29
|
├── native-backup.js # SurrealQL 原生导出 / 导入
|
|
30
30
|
├── facets.js # 多层标签字段、数量限制和候选词库
|
|
31
|
+
├── world.js # facet 交集、世界母体、flow.json
|
|
32
|
+
├── styles.js # 账号风格注册表与提示词块
|
|
33
|
+
├── builtin-styles.js # 内置账号风格种子
|
|
34
|
+
├── prompts/world-mother.md # 世界母体候选提示词
|
|
31
35
|
├── scripts/query.js # 生成前查询数据库
|
|
32
36
|
├── validate.js # 生成后校验 JSONL 格式
|
|
33
37
|
└── scripts/...
|
|
@@ -76,7 +80,7 @@ plugins/fancy-material/
|
|
|
76
80
|
| `settings` | 否 | 0–10 个时代/场景/背景,例如 `现代`、`豪门`、`校园` |
|
|
77
81
|
| `group_id` | 否 | 可选,组件组共用 ID,格式 `group_<类型>_<序号>_v4` |
|
|
78
82
|
| `note` | 否 | 补充内层隐秘设定/第二重身份或一句解释;最多 300 字 |
|
|
79
|
-
| `source` | 是 | `builtin` 或 `other
|
|
83
|
+
| `source` | 是 | `builtin` 或 `other`;`/fancy-material` 生成内置 kind 用 `builtin`,抖音等外部素材用 `other` |
|
|
80
84
|
|
|
81
85
|
`source` 用来区分内置素材和外部素材:`builtin` 的 `kind` 受 58 个类型限制;`other` 可以写任意自定义 `kind`。`subkind` 是可选的二级分类,用于在同一 `kind` 内继续分组(例如抖音清单里的“病理变异”“赛博进化”“红/气场系”)。不再有 `payload`、`summary`、`description`、`core_hook`、`market_diff`、`search_text` 这些复合字段。
|
|
82
86
|
|
|
@@ -107,20 +111,34 @@ plugins/fancy-material/
|
|
|
107
111
|
- `tropes`、`narrative`、`traits`、`roles`、`relations`、`moods`、`settings` 在适用时尽量写 4–10 个;没有就留空数组。
|
|
108
112
|
- 例:都市高武相关素材可以写 `genres: ["都市","高武"]`、`tropes: ["系统流","升级流"]`、`settings: ["现代","都市"]`。
|
|
109
113
|
|
|
110
|
-
### 2.4
|
|
114
|
+
### 2.4 交互式世界母体 + facet 交集
|
|
115
|
+
|
|
116
|
+
旧的位置参数命令已移除:
|
|
117
|
+
|
|
118
|
+
```text
|
|
119
|
+
/fancy-material <素材类型>
|
|
120
|
+
/fancy-material <题材> <素材类型>
|
|
121
|
+
/fancy-material <题材> all
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
现在统一走交互式流程:
|
|
111
125
|
|
|
112
126
|
```text
|
|
113
|
-
/fancy-material
|
|
114
|
-
|
|
115
|
-
|
|
127
|
+
/fancy-material
|
|
128
|
+
→ 6 层 facet 多选(每层第一项“无(不限)”)
|
|
129
|
+
→ 判断题材/场景/情绪/情节/身份/关系
|
|
130
|
+
→ 生成 3 个世界母体候选
|
|
131
|
+
→ 选择 1 个
|
|
132
|
+
→ 选择生成范围和每个 kind 数量
|
|
133
|
+
→ 生成素材
|
|
116
134
|
```
|
|
117
135
|
|
|
118
|
-
|
|
136
|
+
facet 多选是**交集**:同一层选中的每一项都必须同时满足,不是任选其一。
|
|
137
|
+
例如题材同时选 `都市 + 异能 + 脑洞`,每条素材的 `genres` 必须同时包含这三种。
|
|
138
|
+
复合题材会展开成原子题材,例如 `都市异能 → 都市 + 异能`。
|
|
119
139
|
|
|
120
|
-
|
|
121
|
-
-
|
|
122
|
-
- 第二个参数写 `all` 时,插件会把该题材下的全部 58 个 kind 排成队列,逐个生成;source 仍然是 `other`。
|
|
123
|
-
- 同一批只能使用一个 kind;插件在第一轮识别后记住它,后续批次沿用。
|
|
140
|
+
世界母体和本次选择保存在 `<工作区>/.fancy/material/flow.json`。
|
|
141
|
+
素材不够时运行 `/fancy-material continue` 沿用同一世界母体追加;想重新构建世界用 `/fancy-material --fresh`。
|
|
124
142
|
|
|
125
143
|
### 2.5 命名风格适配与二重身份
|
|
126
144
|
|
|
@@ -355,7 +373,9 @@ node plugins/fancy-material/scripts/query.js \
|
|
|
355
373
|
| `material_kind_name_unique` | `kind, name` | 防止同名同类型重复 |
|
|
356
374
|
| `material_name_search` | `name` | 中文 ngram 全文检索 |
|
|
357
375
|
|
|
358
|
-
素材库 schema
|
|
376
|
+
素材库 schema v13 还包含 `douyin_style` 账号风格表、`douyin_account` 账号表和 `douyin_job` 任务表;账号、作品采集/分析/导入状态和素材在同一个数据库里,完整备份/迁移素材库时会一起带走。`douyin_meta` 保存一次性迁移标记。
|
|
377
|
+
|
|
378
|
+
`douyin_style` 一个账号可以有多条风格记录(`style_key` 唯一),保存风格 DNA、命名规则、词汇域、跨 kind 示例、反例和题材兼容度。内置风格在 `plugins/fancy-material/builtin-styles.js`,运行 `/fancy-material` 时会和数据库风格合并;同 `style_key` 以数据库版本优先。`/fancy-douyin list` 会显示账号可用的 style_key、风格名和示例。
|
|
359
379
|
|
|
360
380
|
中文全文检索:
|
|
361
381
|
|
|
@@ -370,10 +390,10 @@ DEFINE ANALYZER material_zh
|
|
|
370
390
|
## 7. fancy-material 命令
|
|
371
391
|
|
|
372
392
|
```text
|
|
373
|
-
/fancy-material
|
|
374
|
-
/fancy-material
|
|
375
|
-
/fancy-material
|
|
376
|
-
/fancy-material
|
|
393
|
+
/fancy-material 交互式:6 层 facet → 3 个世界母体候选 → 范围/数量 → 生成
|
|
394
|
+
/fancy-material continue 沿用上次世界母体、facet、风格和范围,继续追加
|
|
395
|
+
/fancy-material --fresh 重新构建世界母体(旧素材保留,不删除)
|
|
396
|
+
/fancy-material --style <key> 预填账号风格;多个 key 用逗号分隔
|
|
377
397
|
/fancy-material load <文件> 导入 JSONL
|
|
378
398
|
/fancy-material dump 导出 <工作区>/素材库.md
|
|
379
399
|
/fancy-material export [文件] 导出 SurrealDB 原生 SurrealQL 备份(默认 素材库.surql)
|
|
@@ -385,45 +405,24 @@ DEFINE ANALYZER material_zh
|
|
|
385
405
|
|
|
386
406
|
`dump` / `load` 面向 Markdown 清单和 JSONL 素材;`export` / `import` 面向 SurrealDB 原生 SurrealQL 备份。原生备份包含表结构和记录;`import` 会补齐 schema、追加尚不存在的记录,并跳过已经存在的记录 ID,不会覆盖现有素材。
|
|
387
407
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
1. `_novel_topic.json`(最终选题)
|
|
391
|
-
2. `_novel_topic_suggestion.json`(扫榜候选方向选择结果)
|
|
392
|
-
3. 两者都没有时,弹框确认后使用内置全题材(番茄男频 + 女频)
|
|
393
|
-
|
|
394
|
-
不再从 `topic_decision` 里猜题材。
|
|
395
|
-
|
|
396
|
-
不带参数时,插件会覆盖全部 58 个 kind:
|
|
397
|
-
|
|
398
|
-
```text
|
|
399
|
-
每次运行,每个 kind 新增 50 条。
|
|
400
|
-
一个 kind 写满本次的 50 条,再进入下一个 kind。
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
带参数时,只处理指定类型:
|
|
408
|
+
素材题材和方向不再由插件自动写死:
|
|
404
409
|
|
|
405
|
-
|
|
406
|
-
/
|
|
407
|
-
|
|
408
|
-
|
|
410
|
+
1. 用户本次 facet 选择优先;
|
|
411
|
+
2. `_novel_topic_suggestion.json` 的 `genre` / `direction_title` / `positioning` 只作为推荐值和世界母体锚点;
|
|
412
|
+
3. 已存在的 `_novel_topic.json` 在继续/已敲定时作为参考;
|
|
413
|
+
4. fancy-material 不修改这两个选题文件。
|
|
409
414
|
|
|
410
|
-
|
|
415
|
+
`positioning` 是读者承诺和核心矛盾,不是命名词表。插件会要求模型先把它翻译成世界公理、代价、禁忌,再让名字从公理里长出来;禁止把“岗位/值班/工单”这类词直接当 rank_name / skill_name。
|
|
411
416
|
|
|
412
|
-
|
|
413
|
-
每个 kind 拆成多个批次,每批最多 10 条。
|
|
414
|
-
插件发送一批 → LLM 写一个批次文件 → 校验 → 追加导入 → 插件自动发下一批。
|
|
415
|
-
一个 kind 完成本次 50 条后,插件自动切换到下一个 kind。
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
这不是“数据库里每个 kind 最多 50 条”。50 是**每次运行的新增量**:
|
|
417
|
+
默认每个 kind 新增 20 条,每批最多 10 条。数量是**每次运行的追加量**,不是库内上限:
|
|
419
418
|
|
|
420
419
|
```text
|
|
421
|
-
第 1
|
|
422
|
-
第 2
|
|
423
|
-
两次运行后 → 每个 kind 累计
|
|
420
|
+
第 1 次 /fancy-material → 每个 kind 新增 20 条
|
|
421
|
+
第 2 次 /fancy-material continue → 每个 kind 再追加 20 条
|
|
422
|
+
两次运行后 → 每个 kind 累计 40 条
|
|
424
423
|
```
|
|
425
424
|
|
|
426
|
-
|
|
425
|
+
已有素材只用于去重,不会让本次配额减少。中断后用 `/fancy-material continue` 沿用同一世界母体;已导入素材不会撤销。
|
|
427
426
|
|
|
428
427
|
运行中会写入进度文件:
|
|
429
428
|
|
|
@@ -443,16 +442,17 @@ export FANCY_MATERIAL_TARGET_PER_KIND=10
|
|
|
443
442
|
export FANCY_MATERIAL_BATCH_SIZE=5
|
|
444
443
|
```
|
|
445
444
|
|
|
446
|
-
|
|
445
|
+
中断后继续:
|
|
447
446
|
|
|
448
447
|
```text
|
|
449
|
-
|
|
450
|
-
再次运行会开始新一轮 50 条配额;
|
|
451
|
-
不会从上次中断的位置抵扣本次配额。
|
|
448
|
+
/fancy-material continue
|
|
452
449
|
```
|
|
453
450
|
|
|
454
|
-
|
|
455
|
-
|
|
451
|
+
```text
|
|
452
|
+
已经导入的素材保留;
|
|
453
|
+
沿用同一个世界母体、facet、风格和范围;
|
|
454
|
+
本次按新选择的数量继续追加,不删除、不覆盖旧素材。
|
|
455
|
+
```
|
|
456
456
|
|
|
457
457
|
`init` 只补齐 schema/索引,不会清空合法素材;`source=builtin` 且已下线的 kind 会被清理。`remove` 会先弹窗确认,再执行
|
|
458
458
|
`REMOVE DATABASE material_library`,删除后可用 `/fancy-material init` 重建。
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
|
|
19
19
|
若指定了题材风格,在不违背以上原则的前提下遵循对应题材的专属创意规则与命名体例。当前风格规则:{{STYLE_RULES}}
|
|
20
20
|
|
|
21
|
+
{{WORLD_BLOCK}}
|
|
22
|
+
|
|
23
|
+
{{STYLE_BLOCK}}
|
|
24
|
+
|
|
21
25
|
---
|
|
22
26
|
|
|
23
27
|
## 二、原子素材基础模型
|
|
@@ -32,7 +36,7 @@
|
|
|
32
36
|
| `kind` | 是 | {{KIND_RULE}} |
|
|
33
37
|
| `name` | 是 | 素材本体:一句话/一个短语/一个名称,是素材的核心内容 |
|
|
34
38
|
| `tags` | 是 | 3–8 个短标签,严格遵循「标签标准化规则」 |
|
|
35
|
-
| `genres` | 是 | 1–
|
|
39
|
+
| `genres` | 是 | 1–10 个适用题材,必须完整包含当前主题材名;跨题材通用写 `["通用"]` |
|
|
36
40
|
| `group_id` | 否 | 可选,组件组共用 ID,格式 `group_<类型>_<序号>_v4`;同组素材逻辑自洽 |
|
|
37
41
|
| `subkind` | 否 | 可选,kind 下的二级分类,例如 kind=特殊体质、subkind=病理变异;用于同 kind 内再分组 |
|
|
38
42
|
| `note` | 否 | 补充「内层隐秘设定」「第二重身份」或一句必要解释,默认空字符串,最多 300 字 |
|
|
@@ -77,10 +81,12 @@
|
|
|
77
81
|
|
|
78
82
|
### 4.1 总规则:体例后缀必须匹配题材文化体系
|
|
79
83
|
|
|
80
|
-
1.
|
|
81
|
-
2.
|
|
82
|
-
3.
|
|
83
|
-
4.
|
|
84
|
+
1. **世界母体 + facet 交集优先**:先满足「世界母体」中的公理、代价、禁忌与 facet 交集;同一层多选是 AND,不是 OR。作者风格再决定表达方式,题材体例只在两者没有覆盖时兜底。
|
|
85
|
+
2. **作者风格优先**:如果「风格锁定」中选中了账号风格,先满足该风格的长度、句式、修辞与禁用项;题材体例只在风格没有覆盖时兜底。
|
|
86
|
+
3. **主题材决定命名体系**:以第一个题材为核心命名风格基准,其他题材融入核心逻辑,不乱用词缀。
|
|
87
|
+
4. **混合题材适配逻辑**:如「都市+西方哲学+高武」,主风格用都市高武的凝练感,核心意象用西方哲学/宗教元素,禁用中式“诀/式/法”后缀。
|
|
88
|
+
5. **禁止跨体系串用**:西方奇幻禁用中式武侠后缀,古代题材禁用科幻术语,现代题材禁用古奥生僻词。
|
|
89
|
+
6. **都市类二重身份**:地名、势力名、能力名优先写内层隐秘身份;表层日常伪装名写进 `note`。两层身份必须有逻辑关联,不能各写各的。
|
|
84
90
|
|
|
85
91
|
### 4.2 分题材命名体例对照表
|
|
86
92
|
|
|
@@ -494,7 +500,7 @@ node '{{QUERY_SCRIPT}}' --workspace '{{WORKSPACE}}' --search '残影 高速' --l
|
|
|
494
500
|
3. 它有没有具体参照物、感官、情绪或处境?
|
|
495
501
|
4. 它能不能脱离当前人物/武器/场景,单独用在别处?
|
|
496
502
|
5. 它和已有素材是不是同义换皮?
|
|
497
|
-
6. `tags` 是否 3–8 个、覆盖多个维度、能用于检索?`genres` 是否 1–
|
|
503
|
+
6. `tags` 是否 3–8 个、覆盖多个维度、能用于检索?`genres` 是否 1–10 个,并覆盖这个素材能适配的多个题材?
|
|
498
504
|
7. `genres` 是否完整包含本次主题材名?
|
|
499
505
|
8. 命名/措辞/体例是否匹配题材文化体系?有没有跨题材串味?
|
|
500
506
|
9. 都市类地名/势力名/能力名是否有「表层日常身份 + 内层隐秘属性」?`note` 是否补充了表层伪装或内层设定?
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
-- 网文创作素材库 · 原子素材 schema
|
|
1
|
+
-- 网文创作素材库 · 原子素材 schema v13(SurrealDB 2.3+)
|
|
2
2
|
-- 用法:
|
|
3
3
|
-- surreal sql --endpoint http://127.0.0.1:8000 --user root --pass ... \
|
|
4
4
|
-- --namespace fancy --database material_library --multi < schema.surql
|
|
@@ -139,3 +139,42 @@ DEFINE FIELD OVERWRITE updated_at ON douyin_meta TYPE datetime VALUE time::now()
|
|
|
139
139
|
DEFINE INDEX IF NOT EXISTS douyin_meta_key_unique ON douyin_meta FIELDS meta_key UNIQUE;
|
|
140
140
|
|
|
141
141
|
ALTER TABLE douyin_meta PERMISSIONS FOR select, create, update, delete FULL;
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
-- ---------------------------------------------------------------------------
|
|
145
|
+
-- 抖音账号风格(v13)
|
|
146
|
+
--
|
|
147
|
+
-- 一个账号允许多条风格记录(style_key 唯一);内置风格在代码里,
|
|
148
|
+
-- 这里只存从作品提炼/增量 patch 的动态风格。
|
|
149
|
+
-- ---------------------------------------------------------------------------
|
|
150
|
+
DEFINE TABLE IF NOT EXISTS douyin_style SCHEMAFULL;
|
|
151
|
+
|
|
152
|
+
DEFINE FIELD OVERWRITE style_key ON douyin_style TYPE string;
|
|
153
|
+
DEFINE FIELD OVERWRITE account_url ON douyin_style TYPE string;
|
|
154
|
+
DEFINE FIELD OVERWRITE account_name ON douyin_style TYPE option<string>;
|
|
155
|
+
DEFINE FIELD OVERWRITE style_name ON douyin_style TYPE string;
|
|
156
|
+
DEFINE FIELD OVERWRITE style_type ON douyin_style TYPE string DEFAULT 'naming'
|
|
157
|
+
ASSERT $value IN ['naming', 'structure', 'teaching', 'visual'];
|
|
158
|
+
DEFINE FIELD OVERWRITE genre_tags ON douyin_style TYPE array<string> DEFAULT [];
|
|
159
|
+
DEFINE FIELD OVERWRITE dna ON douyin_style TYPE string DEFAULT '';
|
|
160
|
+
DEFINE FIELD OVERWRITE naming_rules ON douyin_style TYPE object DEFAULT {};
|
|
161
|
+
DEFINE FIELD OVERWRITE lexicon ON douyin_style TYPE object DEFAULT {};
|
|
162
|
+
DEFINE FIELD OVERWRITE cross_kind_examples ON douyin_style TYPE object DEFAULT {};
|
|
163
|
+
DEFINE FIELD OVERWRITE anti_examples ON douyin_style TYPE array<string> DEFAULT [];
|
|
164
|
+
DEFINE FIELD OVERWRITE compatibility ON douyin_style TYPE object DEFAULT {};
|
|
165
|
+
DEFINE FIELD OVERWRITE confidence ON douyin_style TYPE number DEFAULT 0;
|
|
166
|
+
DEFINE FIELD OVERWRITE source_works ON douyin_style TYPE int DEFAULT 0;
|
|
167
|
+
DEFINE FIELD OVERWRITE source_materials ON douyin_style TYPE int DEFAULT 0;
|
|
168
|
+
DEFINE FIELD OVERWRITE version ON douyin_style TYPE int DEFAULT 1;
|
|
169
|
+
DEFINE FIELD OVERWRITE status ON douyin_style TYPE string DEFAULT 'active'
|
|
170
|
+
ASSERT $value IN ['active', 'draft', 'failed'];
|
|
171
|
+
DEFINE FIELD OVERWRITE profile_json ON douyin_style TYPE object DEFAULT {};
|
|
172
|
+
DEFINE FIELD OVERWRITE created_at ON douyin_style TYPE datetime DEFAULT time::now();
|
|
173
|
+
DEFINE FIELD OVERWRITE updated_at ON douyin_style TYPE datetime VALUE time::now();
|
|
174
|
+
|
|
175
|
+
DEFINE INDEX IF NOT EXISTS douyin_style_key_unique ON douyin_style FIELDS style_key UNIQUE;
|
|
176
|
+
DEFINE INDEX IF NOT EXISTS douyin_style_account ON douyin_style FIELDS account_url;
|
|
177
|
+
DEFINE INDEX IF NOT EXISTS douyin_style_genres ON douyin_style FIELDS genre_tags;
|
|
178
|
+
DEFINE INDEX IF NOT EXISTS douyin_style_updated_at ON douyin_style FIELDS updated_at;
|
|
179
|
+
|
|
180
|
+
ALTER TABLE douyin_style PERMISSIONS FOR select, create, update, delete FULL;
|
package/docs/workspace-mcp.md
CHANGED
|
@@ -96,8 +96,9 @@ namespace: fancy
|
|
|
96
96
|
### 素材库
|
|
97
97
|
|
|
98
98
|
```text
|
|
99
|
-
/fancy-material #
|
|
100
|
-
/fancy-material
|
|
99
|
+
/fancy-material # 交互式:6 层 facet → 世界母体 → 生成
|
|
100
|
+
/fancy-material continue # 沿用上次世界母体、facet、风格和范围追加素材
|
|
101
|
+
/fancy-material --fresh # 重新构建世界母体(旧素材保留)
|
|
101
102
|
/fancy-material load <文件> # 先校验 JSONL,再追加导入
|
|
102
103
|
/fancy-material dump # 导出 A/素材库.md
|
|
103
104
|
/fancy-material export [文件] # 导出 SurrealDB 原生 SurrealQL 备份(默认 素材库.surql)
|
|
@@ -154,7 +155,7 @@ namespace: fancy
|
|
|
154
155
|
|
|
155
156
|
```text
|
|
156
157
|
/fancy-topic # 选 decision 文件、平台和候选方向 → _novel_topic_suggestion.json
|
|
157
|
-
/fancy-topic setup #
|
|
158
|
+
/fancy-topic setup # fancy-material 之后验收素材 → 1 个推荐定稿 + 2 个备选 → _novel_topic.json
|
|
158
159
|
/fancy-build scale|macro|cast|rhythm|outline|write
|
|
159
160
|
/fancy-export
|
|
160
161
|
```
|
package/lib/material-db.js
CHANGED
|
@@ -17,7 +17,7 @@ import { readSecrets, readWorkspace } from './workspace.js';
|
|
|
17
17
|
import { rpcUrl, startServer } from './surreal-server.js';
|
|
18
18
|
|
|
19
19
|
export const MATERIAL_DATABASE = 'material_library';
|
|
20
|
-
export const MATERIAL_SCHEMA_VERSION =
|
|
20
|
+
export const MATERIAL_SCHEMA_VERSION = 13;
|
|
21
21
|
|
|
22
22
|
const SCHEMA_FILE = fileURLToPath(new URL('../docs/material-library/schema.surql', import.meta.url));
|
|
23
23
|
|
|
@@ -61,7 +61,7 @@ export async function connectMaterial(root) {
|
|
|
61
61
|
/**
|
|
62
62
|
* Ensure the material database and its schema exist. Idempotent.
|
|
63
63
|
*
|
|
64
|
-
* Schema v12 adds the douyin_account table; v11 adds the multi-layer material facets (`subject`, `tropes`, `narrative`, `traits`, `roles`, `relations`, `moods`, `settings`) and keeps the v10 douyin task tables / v9 subkind / v8 note assertion / v7 group_id / 58-kind catalog. Before applying the
|
|
64
|
+
* Schema v13 adds the douyin_style table; v12 adds the douyin_account table; v11 adds the multi-layer material facets (`subject`, `tropes`, `narrative`, `traits`, `roles`, `relations`, `moods`, `settings`) and keeps the v10 douyin task tables / v9 subkind / v8 note assertion / v7 group_id / 58-kind catalog. Before applying the
|
|
65
65
|
* new ASSERT, rows belonging to retired kinds are removed; otherwise SurrealDB
|
|
66
66
|
* refuses to overwrite the field because existing records no longer conform.
|
|
67
67
|
*
|
|
@@ -116,6 +116,13 @@ export async function ensureMaterialDatabase(root) {
|
|
|
116
116
|
if (!accountTable.fields || !accountTable.fields.account_url || !accountTable.fields.added_at) {
|
|
117
117
|
throw new Error('素材库 schema 初始化后仍未找到 douyin_account 账号字段。');
|
|
118
118
|
}
|
|
119
|
+
const styleInfo = await db.query('INFO FOR TABLE douyin_style;');
|
|
120
|
+
const styleTable = Array.isArray(styleInfo) && styleInfo[0] ? styleInfo[0] : {};
|
|
121
|
+
if (!styleTable.fields || !styleTable.fields.style_key || !styleTable.fields.account_url
|
|
122
|
+
|| !styleTable.fields.style_name || !styleTable.fields.style_type
|
|
123
|
+
|| !styleTable.fields.profile_json || !styleTable.fields.naming_rules) {
|
|
124
|
+
throw new Error('素材库 schema 初始化后仍未找到 douyin_style 风格字段。');
|
|
125
|
+
}
|
|
119
126
|
return {
|
|
120
127
|
ok: true,
|
|
121
128
|
namespace,
|
package/package.json
CHANGED
|
@@ -304,7 +304,7 @@ export async function apply(ctx) {
|
|
|
304
304
|
formatWorkspace(result.workspace),
|
|
305
305
|
'',
|
|
306
306
|
'数据库:schema ' + result.schema_version + ' · validation ' + result.validation_version,
|
|
307
|
-
'素材库:' + (result.material?.database || 'material_library') + '(schema ' + (result.material?.schema_version ||
|
|
307
|
+
'素材库:' + (result.material?.database || 'material_library') + '(schema ' + (result.material?.schema_version || 13) + ')',
|
|
308
308
|
'服务:' + (result.server.running ? '运行中' : '未运行'),
|
|
309
309
|
...(result.started && result.started.endpoint_changed
|
|
310
310
|
? ['⚠️ 原端口被另一个 SurrealDB 占用,已改用:' + result.started.endpoint]
|
|
@@ -151,7 +151,7 @@ export async function apply(ctx) {
|
|
|
151
151
|
'✅ 工作区数据库初始化完成',
|
|
152
152
|
'服务:' + (result.server.running ? '运行中' : '未运行'),
|
|
153
153
|
'schema:' + result.schema_version + ' validation:' + result.validation_version,
|
|
154
|
-
'素材库:' + (result.material?.database || 'material_library') + '(schema ' + (result.material?.schema_version ||
|
|
154
|
+
'素材库:' + (result.material?.database || 'material_library') + '(schema ' + (result.material?.schema_version || 13) + ')',
|
|
155
155
|
'项目库:' + result.projects.length + ' 个' + (failed.length ? ',失败 ' + failed.length + ' 个' : ''),
|
|
156
156
|
...failed.map((f) => '❌ ' + f.project.name + ':' + f.error),
|
|
157
157
|
].join('\n'));
|
|
@@ -19,6 +19,8 @@ import { readJsonFile, resolveWorkspace } from '#workspace';
|
|
|
19
19
|
import { connectMaterial, ensureMaterialDatabase } from '#material-db';
|
|
20
20
|
import { MATERIAL_FACET_FIELDS } from '../fancy-material/facets.js';
|
|
21
21
|
import { deployMaterialTools } from '../fancy-material/tool-deploy.js';
|
|
22
|
+
import { loadStyleRegistry, stylesForAccount, upsertStyleProfiles } from '../fancy-material/styles.js';
|
|
23
|
+
import { loadStyleSamplesByAccount, parseStyleDistillResult, styleDistillPrompt, styleResultPath, removeStyleResult } from './style-distill.js';
|
|
22
24
|
import { makeWaitForTurn } from '../fancy-story-builder/writing-driver.js';
|
|
23
25
|
import { deployDouyinTools } from './deploy.js';
|
|
24
26
|
import {
|
|
@@ -885,6 +887,58 @@ function materialFileReady(dir) {
|
|
|
885
887
|
}
|
|
886
888
|
}
|
|
887
889
|
|
|
890
|
+
/**
|
|
891
|
+
* 账号作品全部入库后,按账号提炼/增量 patch 风格。
|
|
892
|
+
* 失败只记日志,不影响采集主流程;只写 douyin_style,不删除任何素材。
|
|
893
|
+
*/
|
|
894
|
+
async function distillStylesForRun({
|
|
895
|
+
root, db, accounts, styleAccounts, runDir, invocation, taskList, signal,
|
|
896
|
+
}) {
|
|
897
|
+
if (!styleAccounts.size) return [];
|
|
898
|
+
const samplesByAccount = await loadStyleSamplesByAccount(db);
|
|
899
|
+
const registry = await loadStyleRegistry(root, { db });
|
|
900
|
+
const results = [];
|
|
901
|
+
for (const account of accounts) {
|
|
902
|
+
if (signal && signal.aborted) break;
|
|
903
|
+
if (!styleAccounts.has(account.url)) continue;
|
|
904
|
+
const samples = samplesByAccount.get(account.url);
|
|
905
|
+
if (!samples || !samples.sourceMaterials) continue;
|
|
906
|
+
const existing = stylesForAccount(registry.styles, account);
|
|
907
|
+
const resultPath = styleResultPath(runDir, account);
|
|
908
|
+
fs.mkdirSync(path.dirname(resultPath), { recursive: true });
|
|
909
|
+
removeStyleResult(resultPath);
|
|
910
|
+
try {
|
|
911
|
+
taskList.progressAt(5, `提炼账号风格(${account.name || account.url})`);
|
|
912
|
+
const prompt = styleDistillPrompt({ account, samples, existing, resultPath });
|
|
913
|
+
const sent = await llmFollowup(invocation, prompt, { appendTempRule: false });
|
|
914
|
+
if (!sent || sent.ok !== true) {
|
|
915
|
+
results.push({ account: account.url, ok: false, error: (sent && sent.error) || '提示词投递失败' });
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
taskList.watchTurns(invocation);
|
|
919
|
+
const wait = makeWaitForTurn(invocation, {
|
|
920
|
+
timeoutMs: 5 * 60 * 1000,
|
|
921
|
+
idleGraceMs: 60 * 1000,
|
|
922
|
+
signal,
|
|
923
|
+
});
|
|
924
|
+
const waited = await wait([resultPath]);
|
|
925
|
+
if (!waited || !waited.ok) {
|
|
926
|
+
results.push({ account: account.url, ok: false, error: (waited && (waited.reason || waited.code)) || '等待风格提炼结果失败' });
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
const profiles = parseStyleDistillResult(fs.readFileSync(resultPath, 'utf8'));
|
|
930
|
+
const saved = await upsertStyleProfiles(db, profiles, { account });
|
|
931
|
+
results.push({ account: account.url, ok: true, styles: saved.map((style) => style.style_key) });
|
|
932
|
+
} catch (err) {
|
|
933
|
+
results.push({ account: account.url, ok: false, error: err && err.message ? err.message : String(err) });
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
for (const result of results.filter((item) => !item.ok)) {
|
|
937
|
+
console.error(`[style-distill] ${result.account}: ${result.error}`);
|
|
938
|
+
}
|
|
939
|
+
return results;
|
|
940
|
+
}
|
|
941
|
+
|
|
888
942
|
async function runCrawl(ctx, invocation, session, taskList) {
|
|
889
943
|
const root = workspaceOf(session);
|
|
890
944
|
const paths = ensureDouyinDir(root);
|
|
@@ -1016,6 +1070,8 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1016
1070
|
|
|
1017
1071
|
queue = useSubagents ? createJobQueue() : null;
|
|
1018
1072
|
const queueStats = { queued: 0, finished: 0 };
|
|
1073
|
+
const styleAccounts = new Map();
|
|
1074
|
+
let styleResults = [];
|
|
1019
1075
|
let scannedAccounts = 0;
|
|
1020
1076
|
let foundNotes = 0;
|
|
1021
1077
|
let foundVideos = 0;
|
|
@@ -1094,6 +1150,7 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1094
1150
|
} else {
|
|
1095
1151
|
inserted += analyzed.inserted || 0;
|
|
1096
1152
|
skippedMaterials += analyzed.skipped || 0;
|
|
1153
|
+
if (job.accountUrl) styleAccounts.set(job.accountUrl, (styleAccounts.get(job.accountUrl) || 0) + Math.max(1, analyzed.inserted || 0));
|
|
1097
1154
|
if (job.jobKey) {
|
|
1098
1155
|
await updateJob(jobStore.db, job.jobKey, {
|
|
1099
1156
|
analysis_status: 'analyzed',
|
|
@@ -1691,6 +1748,16 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1691
1748
|
}
|
|
1692
1749
|
}
|
|
1693
1750
|
|
|
1751
|
+
if (!aborted && styleAccounts.size && process.env.FANCY_DOUYIN_STYLE_DISTILL !== '0') {
|
|
1752
|
+
try {
|
|
1753
|
+
styleResults = await distillStylesForRun({
|
|
1754
|
+
root, db: jobStore.db, accounts, styleAccounts, runDir, invocation, taskList, signal: jobSignal,
|
|
1755
|
+
});
|
|
1756
|
+
} catch (err) {
|
|
1757
|
+
console.error('[style-distill] 提炼账号风格失败:' + (err && err.message ? err.message : String(err)));
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1694
1761
|
taskList.advance(5);
|
|
1695
1762
|
return notify(session, (aborted || failures.length) ? 'error' : 'success', summaryText({
|
|
1696
1763
|
accounts: accounts.length,
|
|
@@ -1713,6 +1780,7 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1713
1780
|
mode: browser.mode,
|
|
1714
1781
|
analysisMode: useSubagents ? 'subagent' : 'single',
|
|
1715
1782
|
subagentWorkers,
|
|
1783
|
+
stylesUpdated: styleResults.filter((item) => item.ok).flatMap((item) => item.styles || []),
|
|
1716
1784
|
}));
|
|
1717
1785
|
} finally {
|
|
1718
1786
|
if (queue) {
|
|
@@ -1758,7 +1826,18 @@ async function runList(session) {
|
|
|
1758
1826
|
const accounts = await listAccounts(store.db);
|
|
1759
1827
|
await migrateCrawledJobs(store.db, root, accounts);
|
|
1760
1828
|
counts = await countJobsByAccount(store.db);
|
|
1761
|
-
|
|
1829
|
+
let stylesByAccount = new Map();
|
|
1830
|
+
try {
|
|
1831
|
+
const registry = await loadStyleRegistry(root, { db: store.db });
|
|
1832
|
+
for (const account of accounts) {
|
|
1833
|
+
const styles = stylesForAccount(registry.styles, account);
|
|
1834
|
+
if (styles.length) {
|
|
1835
|
+
stylesByAccount.set(account.url, styles);
|
|
1836
|
+
if (account.name) stylesByAccount.set(account.name, styles);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
} catch { /* 风格表未初始化时仍显示账号列表 */ }
|
|
1840
|
+
return notify(session, 'success', accountListText(accounts, counts, stylesByAccount));
|
|
1762
1841
|
} finally {
|
|
1763
1842
|
await store.close();
|
|
1764
1843
|
}
|
|
@@ -196,7 +196,7 @@ export function readCrawled(root) {
|
|
|
196
196
|
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
export function accountListText(accountsOrRoot, countsOverride = null) {
|
|
199
|
+
export function accountListText(accountsOrRoot, countsOverride = null, stylesByAccount = new Map()) {
|
|
200
200
|
const accounts = Array.isArray(accountsOrRoot) ? accountsOrRoot : readAccounts(accountsOrRoot);
|
|
201
201
|
if (!accounts.length) {
|
|
202
202
|
return [
|
|
@@ -223,6 +223,29 @@ export function accountListText(accountsOrRoot, countsOverride = null) {
|
|
|
223
223
|
lines.push(`${index + 1}. ${item.url}(未获取账号名/抖音号)`);
|
|
224
224
|
}
|
|
225
225
|
lines.push(` 已采集 ${count} 篇`);
|
|
226
|
+
const styles = stylesByAccount.get(item.url) || stylesByAccount.get(item.name) || [];
|
|
227
|
+
if (!styles.length) {
|
|
228
|
+
lines.push(' 风格:未提炼(运行一次作品分析后自动生成)');
|
|
229
|
+
} else {
|
|
230
|
+
lines.push(' 风格:');
|
|
231
|
+
for (const style of styles.slice(0, 8)) {
|
|
232
|
+
const genres = Array.isArray(style.genre_tags) && style.genre_tags.length
|
|
233
|
+
? '|' + style.genre_tags.join('、')
|
|
234
|
+
: '';
|
|
235
|
+
lines.push(` - ${style.style_key}(${style.style_name})${genres}`);
|
|
236
|
+
if (style.dna) lines.push(' ' + style.dna);
|
|
237
|
+
const examples = [];
|
|
238
|
+
for (const values of Object.values(style.cross_kind_examples || {})) {
|
|
239
|
+
if (!Array.isArray(values)) continue;
|
|
240
|
+
for (const value of values) {
|
|
241
|
+
if (value && !examples.includes(value)) examples.push(value);
|
|
242
|
+
if (examples.length >= 3) break;
|
|
243
|
+
}
|
|
244
|
+
if (examples.length >= 3) break;
|
|
245
|
+
}
|
|
246
|
+
if (examples.length) lines.push(' 示例:' + examples.join('、'));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
226
249
|
});
|
|
227
250
|
return lines.join('\n');
|
|
228
251
|
}
|