@cloud411716/fancy-webnovel 4.28.0 → 4.29.1

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.
@@ -36,8 +36,10 @@ export async function buildExistingIndex(root, genres, stamp) {
36
36
  const records = Array.isArray(rows) && Array.isArray(rows[0]) ? rows[0] : [];
37
37
  const selected = new Set((genres || []).filter(Boolean));
38
38
  const filtered = selected.size
39
- ? records.filter((record) => (Array.isArray(record.genres) ? record.genres : [])
40
- .some((genre) => selected.has(String(genre))))
39
+ ? records.filter((record) => {
40
+ const values = new Set(Array.isArray(record.genres) ? record.genres.map(String) : []);
41
+ return [...selected].every((genre) => values.has(genre));
42
+ })
41
43
  : records;
42
44
  const file = path.join(
43
45
  workspacePaths(root).tmp,
@@ -63,8 +65,8 @@ export async function buildExistingIndex(root, genres, stamp) {
63
65
  /**
64
66
  * Count existing materials per kind for the selected genres.
65
67
  *
66
- * A material can carry several genres. Counting with CONTAINSANY counts each
67
- * material once, unlike summing per-genre counts and double-counting cards.
68
+ * Facet semantics are intersection: a material must contain **all** selected
69
+ * genres. CONTAINSALL counts each matching material once.
68
70
  *
69
71
  * @param {string} root workspace directory
70
72
  * @param {string[]} genres selected genres; empty means all
@@ -74,11 +76,11 @@ export async function countByKind(root, genres) {
74
76
  const { db } = await connectMaterial(root);
75
77
  try {
76
78
  const list = (genres || []).filter(Boolean);
77
- // count() over a CONTAINSANY predicate counts every matching array
78
- // element, not every record. Count ids through a subquery instead.
79
+ // count() over a CONTAINSALL predicate counts every matching record.
80
+ // Subquery keeps the shape identical to the no-filter branch.
79
81
  const rows = list.length
80
82
  ? await db.query(
81
- 'SELECT kind, count() AS n FROM (SELECT id, kind FROM material WHERE genres CONTAINSANY $genres) GROUP BY kind;',
83
+ 'SELECT kind, count() AS n FROM (SELECT id, kind FROM material WHERE genres CONTAINSALL $genres) GROUP BY kind;',
82
84
  { genres: list },
83
85
  )
84
86
  : await db.query('SELECT kind, count() AS n FROM material GROUP BY kind;');
@@ -103,7 +105,7 @@ export async function countKind(root, kind, genres) {
103
105
  const list = (genres || []).filter(Boolean);
104
106
  const rows = list.length
105
107
  ? await db.query(
106
- 'SELECT count() AS n FROM (SELECT VALUE id FROM material WHERE kind = $kind AND genres CONTAINSANY $genres) GROUP ALL;',
108
+ 'SELECT count() AS n FROM (SELECT VALUE id FROM material WHERE kind = $kind AND genres CONTAINSALL $genres) GROUP ALL;',
107
109
  { kind, genres: list },
108
110
  )
109
111
  : await db.query(
@@ -0,0 +1,81 @@
1
+ # 世界母体候选生成
2
+
3
+ 你是一位网文世界的总设定师。你现在的任务不是写素材,而是先造一个能长出素材的世界母体。
4
+
5
+ 工作区:`{{WORKSPACE}}`
6
+
7
+ ## 一、本次选择
8
+
9
+ {{FACET_BLOCK}}
10
+
11
+ ## 二、选题建议
12
+
13
+ {{SUGGESTION_BLOCK}}
14
+
15
+ ## 三、风格
16
+
17
+ {{STYLE_BLOCK}}
18
+
19
+ ## 四、生成 3 个世界母体候选
20
+
21
+ 必须生成**恰好 3 个**候选,三个候选的差异要落在世界运转方式上,而不是只换名字:
22
+
23
+ 1. `suggestion_anchor`:优先兑现选题建议的方向和定位。
24
+ 2. `facet_driven`:优先兑现用户选择的 facet 交集。
25
+ 3. `wildcard`:仍然满足全部 facet,但换一种更反常识的世界运转方式。
26
+
27
+ 每个候选都必须同时满足:用户选中的全部题材、场景、情绪、情节、身份、关系。
28
+ **同一层多选是交集,不是并集。** 例如同时选 都市 + 异能 + 脑洞,世界必须同时是都市、异能、脑洞,不能只取其中一个。
29
+
30
+ ### 命名质量红线
31
+
32
+ - 世界母体不是现实公司的换皮。不要用“夜班、值班、保安、物业、工单、培训手册”直接当世界观核心。
33
+ - 不要生成“试岗、替班、带班、值守”这种现实职级名。
34
+ - 不要生成“包月令、静音条”这种“日常词 + 后缀”的字面功能名。
35
+ - `positioning` 是读者承诺,不是词表;先把它翻译成世界公理、代价、禁忌,再让名字从公理里长出来。
36
+ - 名字要有画面、有第二层含义,换一个世界就不成立。
37
+
38
+ ## 五、输出格式
39
+
40
+ 只输出 JSON,不要 Markdown 解释。把 JSON 写入绝对路径:
41
+
42
+ `{{RESULT_PATH}}`
43
+
44
+ 格式:
45
+
46
+ ```json
47
+ {
48
+ "candidates": [
49
+ {
50
+ "candidate_type": "suggestion_anchor",
51
+ "world_id": "stable_ascii_slug",
52
+ "title": "世界母体名",
53
+ "logline": "一句话世界",
54
+ "core_conflict": "这个世界最核心、无法调和的矛盾",
55
+ "reader_promise": "读者会得到的核心体验",
56
+ "power_source": "力量/异常从哪来",
57
+ "cost": "使用力量或维持秩序必须付出的代价",
58
+ "world_rules": ["世界公理 1", "世界公理 2", "世界公理 3"],
59
+ "institutions": ["机构/场所 1", "机构/场所 2"],
60
+ "taboos": ["禁忌 1", "禁忌 2"],
61
+ "visual_motifs": ["视觉母题 1", "视觉母题 2"],
62
+ "naming_logic": "这个世界的人如何命名等级、技能、组织、物品",
63
+ "core_genres": ["必须包含全部选中题材"],
64
+ "supported_kinds": ["rank_name", "skill_name", "faction_name", "item_name", "world_rule"],
65
+ "suggestion_fit": "它如何兑现 direction_title 和 positioning",
66
+ "difference": "与另外两个候选的核心差异"
67
+ }
68
+ ]
69
+ }
70
+ ```
71
+
72
+ 要求:
73
+
74
+ - `core_genres` 必须包含用户选中的全部核心题材,不能漏。
75
+ - `world_rules` 至少 3 条,必须能推出素材,不是空泛口号。
76
+ - `cost` 必须具体到日常动作或关系后果。
77
+ - `naming_logic` 要说明“等级/技能/组织/物品”各自的命名语法,不要只写“有古风感”。
78
+ - 三个候选的 `core_conflict`、`power_source`、`cost` 至少有两项明显不同。
79
+ - 写完后只回复:已写入 <目标文件路径>。
80
+
81
+ {{PREVIOUS_BLOCK}}
@@ -21,12 +21,11 @@ export function helpText() {
21
21
  }).join('\n');
22
22
  return `🧩 素材库 用法
23
23
 
24
- /fancy-material 生成全部素材类型:${MATERIAL_KINDS.length} 个 kind,每个新增 50 条
25
- /fancy-material <素材类型> 只生成指定类型,例如:/fancy-material 地名
26
- /fancy-material <题材> <素材类型> 自定义题材+素材类型,source=other,例如:/fancy-material 都市高武 地名
27
- /fancy-material <题材> all 生成该题材下全部 58 个 kind,source=other,例如:/fancy-material 都市高武 all
24
+ /fancy-material 交互式:逐步选择 6 层 facet → 3 个世界母体候选 → 生成范围/数量 → 生成素材
25
+ /fancy-material continue 沿用上次的世界母体、facet、风格和范围,继续追加素材
26
+ /fancy-material --fresh 重新构建世界母体(旧素材保留,不删除)
28
27
  /fancy-material --style <key> ... 手动指定账号风格;多个用逗号分隔,例如 --style suci,crazy-fish
29
- 不指定时按题材自动选 2-3 个兼容风格
28
+ 不指定时在交互流程里选择:自动 / 不使用 / 具体 key
30
29
  /fancy-material load <文件.jsonl> 导入 JSONL;导入前先校验格式
31
30
  /fancy-material init 创建/补齐素材库 schema、索引和查询/校验脚本
32
31
  /fancy-material remove 删除整个素材库(会二次确认)
@@ -43,17 +42,18 @@ export function helpText() {
43
42
  - note 可选,最多 300 字;都市类地名/势力/能力名优先写内层身份,表层伪装名写 note。
44
43
  - 命名/措辞按题材文化体系适配:东方仙侠用诀/式/法/印,都市高武用令/条/章/程,西幻用契/印/律/颂,科幻用协议/阈值/序列,历史用司/署/营/旗,悬疑用规则/现象/编号,言情以意象词为主。
45
44
  - 禁止用质量评价词做 tags:精品、高价值、文笔好、强力、神秘。
46
- - tags 和 genres 都是数组:tags 3–8 个,genres 1–5 个;一个素材可以同时适配多个题材/标签。
47
- - 每次运行:每个 kind 新增 50 条;每批最多 10 条,插件自动分批直到完成。
48
- - 风格来源:内置风格库 + 数据库 douyin_style,按题材自动选 2-3 个;可用 --style 手动覆盖。
45
+ - tags 和 genres 都是数组:tags 3–8 个,genres 1–10 个;一个素材可以同时适配多个题材/标签。
46
+ - 每次运行默认每个 kind 新增 20 条;每批最多 10 条,插件自动分批直到完成。
47
+ - facet 多选是**交集**:同一层选中的每一项都必须同时满足,不是任选其一。例如题材选 都市+异能+脑洞,素材必须同时满足三种。
48
+ - 选「都市异能」会同时按「都市」和「异能」处理;选「悬疑脑洞」会同时按「悬疑」和「脑洞」处理,两个条件都必须满足。
49
+ - 题材/方向/定位来自 _novel_topic_suggestion.json 时只做推荐值;用户本次选择优先,fancy-material 不修改该文件。
50
+ - 世界母体保存在 <工作区>/.fancy/material/flow.json;continue 会沿用它,不删除旧素材。
51
+ - 风格来源:内置风格库 + 数据库 douyin_style;交互流程里可选自动、不使用或具体 key,也可用 --style 预填。
49
52
  - 用 /fancy-douyin list 查看账号的 style_key、风格名和示例。
50
- - 未指定类型:${MATERIAL_KINDS.length} 个 kind 全部排队。
51
- - 题材来源:优先 _novel_topic.json,其次 _novel_topic_suggestion.json;都没有时弹框确认后使用内置全题材。
52
- - 指定类型:只生成指定 kind,题材来源不变,source=builtin。
53
- - 自定义题材+素材类型:题材和素材类型都可以随便写,插件把它们交给 LLM;第二个参数写 all 表示全部 58 个 kind。生成结果 source=other,不占用内置 kind 目录。
54
- - 不设库内上限:运行两次就是每个 kind 累计 100 条;已有素材只用于去重。
55
- - 中断后重跑会开始新一轮 50 条配额,已经导入的素材不会撤销。
53
+ - 不设库内上限:运行两次就是每个 kind 累计追加;已有素材只用于去重。
54
+ - 中断后继续用 /fancy-material continue 沿用同一世界;已经导入的素材不会撤销。
56
55
  - 只追加,不覆盖;同 kind 同 name 的素材会被跳过。
56
+ - 旧的 /fancy-material <素材类型>、<题材> <素材类型>、<题材> all 已移除。
57
57
  - dump / load 面向 Markdown 清单和 JSONL 素材;export / import 面向 SurrealDB 原生 SurrealQL 备份。
58
58
  - 原生 import 会补齐 schema,并追加备份中尚不存在的记录;相同记录 ID 已存在时自动跳过,不会覆盖。
59
59
  - 全文索引:name(中文 ngram);tags / genres 精确过滤。
@@ -67,7 +67,7 @@ ${genreBlock}
67
67
  ${kindBlock}`;
68
68
  }
69
69
 
70
- export const DEFAULT_TARGET_PER_KIND = 50;
70
+ export const DEFAULT_TARGET_PER_KIND = 20;
71
71
  export const DEFAULT_BATCH_SIZE = 10;
72
72
 
73
73
  /**
@@ -93,15 +93,16 @@ function compactRules(genres, queryScript, workspace, sourceFixed = 'builtin') {
93
93
  '- 每条必须独立、具体、可复用;拒绝“火红、耀眼、神秘、强大”这类空泛词。',
94
94
  '- 命名类必须有具体锚点;拒绝“复原眼、章眼、旧仓单、神秘剑、黑色长刀”这类废名。',
95
95
  '- 字段只能是 id / kind / name / tags / genres / group_id / subkind / note / source;'
96
- + 'source 写 ' + sourceFixed + ';tags 3–8 个,genres 1–5 个。',
96
+ + 'source 写 ' + sourceFixed + ';tags 3–8 个,genres 1–10 个。',
97
97
  '- tags 和 genres 都是数组:一个素材能适配多个题材/标签时,把它们都写进去;'
98
98
  + '例如「都市高武」可以写 tags: ["都市","高武","都市高武", ...]。',
99
99
  '- 命名/措辞/体例必须匹配题材文化体系,禁止跨题材串用后缀。',
100
+ '- facet 多选是交集:同一层选中的每一项都必须同时成立,不能只取其中一个;能写进对应 facet 数组的,要原样写全。',
100
101
  '- 都市类地名/势力/能力名优先写内层身份,表层日常伪装名写 note;note 最多 300 字。',
101
102
  '- tags 不能用质量评价词:精品、高价值、文笔好、强力、神秘。',
102
103
  ];
103
104
  if (Array.isArray(genres) && genres.length) {
104
- lines.push('- genres 必须原样包含本次题材之一:' + genres.join('、'));
105
+ lines.push('- genres 必须原样包含本次全部题材:' + genres.join('、') + ';缺任何一个都算废稿。');
105
106
  }
106
107
  if (queryScript) {
107
108
  lines.push('- 生成前查询已有素材:`node \'' + queryScript + '\' --workspace \'' + workspace
@@ -139,6 +140,8 @@ export function generationPrompt({
139
140
  customKindPending = false,
140
141
  sourceFixed = 'builtin',
141
142
  styleSummary = '',
143
+ worldBlock = '',
144
+ worldSummary = '',
142
145
  }) {
143
146
  const lines = [];
144
147
  if (includeBase && base) {
@@ -147,6 +150,7 @@ export function generationPrompt({
147
150
  lines.push('## 继续生成(同一素材库)', '');
148
151
  lines.push('继续遵守最初提示词中的角色、写作原则、质量红线、命名标准、描写标准、查询与追加规则。不要重新解释规则,直接写本批素材。', '');
149
152
  lines.push(...compactRules(genres, queryScript, workspace, sourceFixed), '');
153
+ if (worldSummary) lines.push('## 本批世界母体锁定(必须保持)', '', worldSummary, '');
150
154
  }
151
155
 
152
156
  if (styleSummary) {
@@ -160,13 +164,24 @@ export function generationPrompt({
160
164
  ? 'topic(_novel_topic.json)'
161
165
  : mode === 'suggestion'
162
166
  ? 'suggestion(_novel_topic_suggestion.json)'
163
- : mode === 'builtin'
164
- ? 'builtin(内置全题材)'
165
- : mode === 'other'
166
- ? 'other(用户自定义题材 + 素材类型)'
167
- : String(mode || '未指定');
167
+ : mode === 'world'
168
+ ? 'world(世界母体 + facet 交集)'
169
+ : mode === 'builtin'
170
+ ? 'builtin(内置全题材)'
171
+ : mode === 'other'
172
+ ? 'other(用户自定义题材 + 素材类型)'
173
+ : String(mode || '未指定');
168
174
  lines.push('- 题材模式:' + modeLabel);
169
- if (Array.isArray(genres) && genres.length) lines.push('- 本次题材:' + genres.join('、'));
175
+ if (worldBlock && includeBase) {
176
+ // 世界母体已经包含在 base 里;这里只提醒本批仍受它约束。
177
+ lines.push('- 世界母体:见上方「世界母体(最高优先级)」;本批所有素材都必须从该母体推导。');
178
+ }
179
+ if (Array.isArray(genres) && genres.length) {
180
+ lines.push('- 本次题材(全部同时满足):' + genres.join('、'));
181
+ lines.push('- 题材交集规则:以上每一项都必须出现在素材的 genres 里;不是任选其一。');
182
+ } else {
183
+ lines.push('- 本次题材:无限制;按世界母体推导,但每条素材仍要写 1–10 个 genres。');
184
+ }
170
185
  if (custom) {
171
186
  lines.push('- 用户素材类型:' + (custom.allKinds ? 'all(全部 ' + MATERIAL_KINDS.length + ' 个素材类型)' : custom.materialType));
172
187
  lines.push('- 素材来源:**other**(用户自定义素材,不是内置目录)');
@@ -207,6 +222,7 @@ export function generationPrompt({
207
222
  lines.push('写入要求:');
208
223
  lines.push('1. 只把 JSONL 写进目标文件,一行一个对象;字段只能是 id / kind / name / tags / genres / group_id / subkind / note / source,source 固定写 ' + sourceFixed + '。tags 和 genres 都是数组:一个素材能适配多个题材/标签时,把它们都写进去(例如 都市高武 → 都市、高武、都市高武)。');
209
224
  lines.push('2. 命名/措辞/体例必须匹配题材文化体系,禁止跨题材串用后缀;都市类地名/势力/能力名优先写内层身份,表层日常伪装名写 note(最多 300 字)。');
225
+ lines.push('2.1 本次 facet 是交集:同一层多选全部同时成立;素材必须同时满足所有选中层,不能只取一部分。选中的 tropes / moods / settings / roles / relations 要原样写进对应数组。');
210
226
  lines.push('3. tags 不能用质量评价词:精品、高价值、文笔好、强力、神秘。');
211
227
  lines.push('4. 不要在文件里写 Markdown 代码围栏、标题、解释、前后缀。');
212
228
  lines.push('5. 可以直接写 JSONL,也可以使用 Python/Node 生成器;生成器放 <工作区>/.tmp/,输出必须是目标 JSONL。');
@@ -262,6 +278,8 @@ export function generationRunText({
262
278
  total,
263
279
  progressFile,
264
280
  styles = [],
281
+ worldTitle = '',
282
+ flowFile = '',
265
283
  aborted = false,
266
284
  stopReason = '',
267
285
  }) {
@@ -288,14 +306,18 @@ export function generationRunText({
288
306
  lines.push('本次新增:' + importedTotal + ' 条');
289
307
  if (Number.isFinite(total)) lines.push('库中素材:' + total + ' 条');
290
308
  if (batches) lines.push('已导入批次:' + batches + ' 批');
309
+ if (worldTitle) lines.push('本次世界母体:' + worldTitle);
291
310
  if (Array.isArray(styles) && styles.length) {
292
311
  lines.push('本次风格:' + styles.map((style) => `${style.style_key}(${style.style_name})`).join('、'));
293
312
  }
294
313
  if (Number.isFinite(elapsedMs) && elapsedMs > 0) lines.push('耗时:' + formatDuration(elapsedMs));
295
314
  if (stopReason) lines.push('停止原因:' + stopReason);
296
315
  if (progressFile) lines.push('进度文件:' + progressFile);
316
+ if (flowFile) lines.push('世界状态:' + flowFile);
297
317
  if (aborted || incomplete.length || notStarted.length || stopReason) {
298
- lines.push('再次运行 /fancy-material 会开始新一轮配额;已导入素材不会撤销。');
318
+ lines.push('继续追加:/fancy-material continue(沿用本次世界母体);已导入素材不会撤销。');
319
+ } else {
320
+ lines.push('素材不够?运行 /fancy-material continue 沿用本次世界母体继续生成。');
299
321
  }
300
322
  return lines.join('\n');
301
323
  }