@cloud411716/fancy-webnovel 4.30.13 → 4.30.15

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.
Files changed (38) hide show
  1. package/docs/material-library/manual/00-core.md +85 -0
  2. package/docs/material-library/manual/01-carrier.md +43 -0
  3. package/docs/material-library/manual/02-wrongness.md +70 -0
  4. package/docs/material-library/manual/03-hidden-world.md +52 -0
  5. package/docs/material-library/manual/04-naming.md +50 -0
  6. package/docs/material-library/manual/05-note.md +36 -0
  7. package/docs/material-library/manual/06-revision.md +31 -0
  8. package/docs/material-library/manual/07-surprise.md +88 -0
  9. package/docs/material-library/manual/cases/boundary.md +38 -0
  10. package/docs/material-library/manual/cases/credential.md +38 -0
  11. package/docs/material-library/manual/cases/document.md +32 -0
  12. package/docs/material-library/manual/cases/record.md +38 -0
  13. package/docs/material-library/manual/cases/ritual.md +32 -0
  14. package/docs/material-library/manual/cases/transaction.md +32 -0
  15. package/docs/material-library/manual/failures/event-summary.md +30 -0
  16. package/docs/material-library/manual/failures/formulaic.md +30 -0
  17. package/docs/material-library/manual/failures/naked-process.md +34 -0
  18. package/docs/material-library/manual/failures/name-only.md +33 -0
  19. package/docs/material-library/manual/index.json +205 -0
  20. package/docs/material-library/manual/palettes/scifi.md +27 -0
  21. package/docs/material-library/manual/palettes/suspense.md +27 -0
  22. package/docs/material-library/manual/palettes/urban.md +27 -0
  23. package/docs/material-library/manual/palettes/western-fantasy.md +27 -0
  24. package/docs/material-library/manual/palettes/xianxia.md +27 -0
  25. package/docs/material-library/manual/patterns/boundary.md +29 -0
  26. package/docs/material-library/manual/patterns/credential.md +29 -0
  27. package/docs/material-library/manual/patterns/document.md +29 -0
  28. package/docs/material-library/manual/patterns/record.md +29 -0
  29. package/docs/material-library/manual/patterns/ritual.md +29 -0
  30. package/docs/material-library/manual/patterns/transaction.md +29 -0
  31. package/docs/material-library/prompt.md +20 -3
  32. package/docs/material-library/quality-spec.md +3 -1
  33. package/package.json +1 -1
  34. package/plugins/fancy-material/builtin-styles.js +2 -1
  35. package/plugins/fancy-material/index.js +31 -2
  36. package/plugins/fancy-material/manual.js +157 -0
  37. package/plugins/fancy-material/styles.js +4 -0
  38. package/plugins/fancy-material/templates.js +4 -0
@@ -235,7 +235,24 @@
235
235
  - 科幻:时间存根、记忆余额。
236
236
  - 悬疑:死者回执、失踪名单。
237
237
 
238
- ### 5.0.1 里世界(硬要求)
238
+ ### 5.0.1 标志性规则(硬要求)
239
+
240
+ 每条 note 必须有一句能被读者复述的标志性异常规则。
241
+
242
+ - 不是“这个物件有灵/有诅咒/有代价”。
243
+ - 不是“某机构 + 某代价”。
244
+ - 必须有一个具体画面/数字/颜色/动作:负数、倒数、蓝灯、坟场、最后一排靠窗、特殊硬币、异世界电话。
245
+ - 第一个想到的规则丢掉;至少写三个候选,选最具体、最有画面、最不官僚的那个。
246
+
247
+ 例:
248
+
249
+ ```text
250
+ 电话亭:投一枚特殊硬币,能接通异世界的电话。
251
+ 红绿灯:数字倒着走,走到 -18 就能到达地狱。
252
+ 校车:最后一排靠窗的位置不能坐,谁坐谁死于非命。
253
+ ```
254
+
255
+ ### 5.0.2 里世界(硬要求)
239
256
 
240
257
  每个能力名背后都要有一个里世界,不能只有“物件 + 个人倒霉”。
241
258
 
@@ -297,8 +314,8 @@ note 至少写清:
297
314
 
298
315
  ### 5.1.1 痕迹多样性(硬要求)
299
316
 
300
- - 同一批 10 条:同一结尾痕迹字最多 2 条;同一双字后缀最多 2 条。
301
- - 同一分系累计 20 条:同一结尾字最多 4 条;至少出现 8 种结尾;四字名最多 18 条;至少 2 条五字以上。
317
+ - 同一批 10 条:同一开头字最多 2 条;同一结尾痕迹字最多 2 条;同一双字后缀最多 2 条。
318
+ - 同一分系累计 20 条:同一开头字最多 4 条;同一结尾字最多 4 条;至少出现 8 种结尾;四字名最多 18 条;至少 2 条五字以上。
302
319
  - A/B/C 三种句式都要出现,不能 10 条全是“器物 + 残痕”。
303
320
  - 不得原样复用 5.1 的示例名;示例只用于理解形态。
304
321
  - 如果本批触发了多样性硬校验,按失败信息重写,不要只换同义词。
@@ -364,7 +364,7 @@ note 没产生的痕迹,不能写进 name。
364
364
 
365
365
  ---
366
366
 
367
- ### 5.6 名字自带高概念
367
+ ### 5.6 名字自带高概念与标志性规则
368
368
 
369
369
  名字不能只是“日常载体 + 普通状态”:
370
370
 
@@ -382,6 +382,8 @@ note 没产生的痕迹,不能写进 name。
382
382
 
383
383
  能力名背后必须有一个里世界:表层日常功能 + 里层隐藏世界/组织/交易/身份。note 要写清谁在用、交换什么、入口/规则/代价/漏洞;只有“物件 + 个人倒霉”,废。
384
384
 
385
+ 每条 note 还必须有一句能被复述的**标志性异常规则**:负数、倒数、颜色变化、多出的一站、禁止的动作、特殊硬币、坟场、异世界入口。第一个想到的规则丢掉,至少写三个候选,选最具体、最有画面的那个。只是“某机构 + 某代价”的,重写。
386
+
385
387
  ---
386
388
 
387
389
  ## 6. Note 的四段式
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "4.30.13",
3
+ "version": "4.30.15",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -136,10 +136,11 @@ export const BUILTIN_STYLES = [
136
136
  forbidden: ['纯工具名词直接入库', '无边界修饰的机务段/信号楼/电梯/业委会/快递柜', '裸载体当名字'],
137
137
  trace_hints: ['隅', '痕', '烬', '残', '余', '赊', '契', '诺', '印', '留', '封', '录'],
138
138
  trace_forbidden: ['分钟', '刻', '一日', '一次', '满格', '最后', '持续'],
139
- trace_diversity: ['同一批 10 条:同一结尾痕迹字最多 2 条,同一双字后缀最多 2 条', '同一分系累计 20 条:同一结尾字最多 4 条,至少 8 种结尾,四字名最多 18 条,至少 2 条五字以上', 'A/B/C 三种句式都要出现,不能全是器物残痕', '不得原样复用示例名'],
139
+ trace_diversity: ['同一批 10 条:同一结尾痕迹字最多 2 条,同一双字后缀最多 2 条', '同一分系累计 20 条:同一开头字最多 4 条,同一结尾字最多 4 条,至少 8 种结尾,四字名最多 18 条,至少 2 条五字以上', 'A/B/C 三种句式都要出现,不能全是器物残痕', '不得原样复用示例名'],
140
140
  trace_grounding: ['名字里的痕迹必须是 note 里那场事件真实留下的东西', '名字含炉→note 必须出现炉;名字以烬结尾→note 必须有可燃物/灰/烧完', '名字以印/契/录/香结尾→note 必须有对应的印痕/契约/册档/气味'],
141
141
  trace_high_concept: ['名字不能只是“日常载体 + 普通状态”(交通卡余额、澡堂旧牌、餐盘余汁)', '名字必须自带一个世界/规则/制度/债务/身份/异常边界的关系词:异、鬼、神、仙、魔、妖、灵、愿、祀、契、约、诺、债、赊、封、禁、界、籍、谱、录、榜、令、判、证、符、咒、阵、劫、缘、命、魂、魄、尸、棺、庙、祠、观、寺、隅、限、期、签、单、条、据、状、书、印、章、戳、票、券、档、案、册、簿、账、款、罚、税、押、保、征信、公告、登记、合同、存根、回执、通知、决定、调解、判决、公证、委托、授权、申请、体检、签收、酒测、行程、户籍、拍卖、生死、死亡、离婚、结婚、房产、营业、许可、通行、身份、工作、学生、社保、医保、香、火、炉、金、漆、孔', '参考方向:异界里程、鬼市手牌、末班鬼公交、剑冢余诺、龙契余烬、时间存根、死者回执'],
142
142
  trace_hidden_world: ['note 必须写出一个隐藏世界/组织/交易/身份:谁在用、交换什么、入口/规则/代价是什么', '只有“物件 + 个人倒霉”,没有里世界,废'],
143
+ trace_surprise: ['每条 note 必须有一句能被读者复述的标志性异常规则', '第一个想到的规则丢掉;至少写三个候选,选最具体、最有画面、最不官僚的那个', '规则里至少有一个视觉锚点:负数/倒数/颜色变化/多出的一站/禁止的动作/特殊硬币/坟场/异界入口', '如果规则只是“某机构 + 某代价”,重写'],
143
144
  tone: '日常、冷静、略带荒诞',
144
145
  },
145
146
  lexicon: {
@@ -57,6 +57,7 @@ import {
57
57
  writeMaterialFlow,
58
58
  } from './world.js';
59
59
  import { exportMaterialDatabase, importMaterialDatabase } from './native-backup.js';
60
+ import { renderManualBlock } from './manual.js';
60
61
  import { nextBatchRequest } from './queue.js';
61
62
  import { ABILITY_CORE_KINDS, buildGenerationItems, planGenerationQueue } from './plan.js';
62
63
  import { deployMaterialTools } from './tool-deploy.js';
@@ -410,8 +411,12 @@ export function chargingBarNameDiversityProblem(records, primaryStyleKey = '', o
410
411
 
411
412
  const endings = countNameValues(all.map((name) => name.slice(-1)));
412
413
  const suffixes = countNameValues(all.map((name) => name.slice(-2)));
414
+ const prefixes = countNameValues(all.map((name) => name.slice(0, 1)));
415
+ const prefixes2 = countNameValues(all.map((name) => name.slice(0, 2)));
413
416
  const maxSameEnding = Math.max(2, Math.ceil(all.length * 0.2));
414
417
  const maxSameSuffix = Math.max(2, Math.ceil(all.length * 0.15));
418
+ const maxSamePrefix = Math.max(2, Math.ceil(all.length * 0.2));
419
+ const maxSamePrefix2 = Math.max(2, Math.ceil(all.length * 0.15));
415
420
  const minEndings = Math.max(4, Math.ceil(all.length * 0.4));
416
421
  const problems = [];
417
422
 
@@ -425,6 +430,16 @@ export function chargingBarNameDiversityProblem(records, primaryStyleKey = '', o
425
430
  problems.push(`双字后缀「${suffix}」${count} 条(上限 ${maxSameSuffix})`);
426
431
  }
427
432
  }
433
+ for (const [prefix, count] of prefixes) {
434
+ if (count > maxSamePrefix) {
435
+ problems.push(`开头字「${prefix}」${count} 条(上限 ${maxSamePrefix})`);
436
+ }
437
+ }
438
+ for (const [prefix, count] of prefixes2) {
439
+ if (count > maxSamePrefix2) {
440
+ problems.push(`双字开头「${prefix}」${count} 条(上限 ${maxSamePrefix2})`);
441
+ }
442
+ }
428
443
  if (endings.size < minEndings) {
429
444
  problems.push(`结尾字只有 ${endings.size} 种(至少 ${minEndings} 种)`);
430
445
  }
@@ -445,14 +460,18 @@ export function chargingBarNameDiversityProblem(records, primaryStyleKey = '', o
445
460
  const offenders = current.filter((name) => {
446
461
  const ending = name.slice(-1);
447
462
  const suffix = name.slice(-2);
463
+ const prefix = name.slice(0, 1);
464
+ const prefix2 = name.slice(0, 2);
448
465
  return (endings.get(ending) || 0) > maxSameEnding
449
- || (suffixes.get(suffix) || 0) > maxSameSuffix;
466
+ || (suffixes.get(suffix) || 0) > maxSameSuffix
467
+ || (prefixes.get(prefix) || 0) > maxSamePrefix
468
+ || (prefixes2.get(prefix2) || 0) > maxSamePrefix2;
450
469
  });
451
470
  return '命名多样性不合格:' + problems.join(';')
452
471
  + (offenders.length
453
472
  ? '。本批需要重写:' + [...new Set(offenders)].slice(0, 8).map((name) => `「${name}」`).join('、')
454
473
  : '')
455
- + '。同一个分系内不能反复用同一套痕迹后缀;请混用器物残痕、边界错位、债契遗存三种句式,并让四字名和五字以上名字都有。';
474
+ + '。同一个分系内不能反复用同一套开头/结尾;请混用器物残痕、边界错位、债契遗存三种句式,并让四字名和五字以上名字都有。';
456
475
  }
457
476
 
458
477
  /** 每种痕迹后缀必须能由名字里的载体产生;这里只拦明显不可能的搭配。 */
@@ -1672,6 +1691,15 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
1672
1691
  String(index + 1).padStart(3, '0') + '_' + (item.kind || item.mode) + '_' + String(batchNo).padStart(2, '0') + '.jsonl',
1673
1692
  );
1674
1693
  const includeBase = batchNo === 1 || batchNo % FULL_PROMPT_EVERY === 1;
1694
+ const manualBlock = item.mode === 'kind'
1695
+ ? renderManualBlock({
1696
+ kind: item.kind,
1697
+ subkind: item.subkind || '',
1698
+ genres,
1699
+ seed: `${batchId}:${item.key || item.kind}:${batchNo}`,
1700
+ compact: !includeBase,
1701
+ })
1702
+ : '';
1675
1703
  let attemptDetail = '';
1676
1704
  let accepted = false;
1677
1705
 
@@ -1766,6 +1794,7 @@ export async function runGenerationWithPlan(ctx, invocation, session, taskList,
1766
1794
  styleSummary,
1767
1795
  worldBlock,
1768
1796
  worldSummary,
1797
+ manualBlock,
1769
1798
  subkind: item.subkind || '',
1770
1799
  groupId: item.group_id || '',
1771
1800
  worldId,
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Material-generation handbook loader.
3
+ *
4
+ * The handbook is split into a fixed core, structural cases, genre palettes,
5
+ * pattern cards, and failure diagnoses. Only the relevant slices are assembled
6
+ * into one batch prompt, so the same core works across genres.
7
+ */
8
+
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+
13
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
+ export const MANUAL_DIR = path.resolve(__dirname, '..', '..', 'docs', 'material-library', 'manual');
15
+ const INDEX_FILE = path.join(MANUAL_DIR, 'index.json');
16
+
17
+ const NAMING_KINDS = new Set([
18
+ 'ability_name', 'skill_name', 'place_name', 'faction_name',
19
+ 'item_name', 'monster_name', 'mythic_being', 'nickname',
20
+ ]);
21
+
22
+ function readFile(file) {
23
+ try {
24
+ return fs.readFileSync(file, 'utf8').trim();
25
+ } catch {
26
+ return '';
27
+ }
28
+ }
29
+
30
+ function loadIndex() {
31
+ try {
32
+ return JSON.parse(fs.readFileSync(INDEX_FILE, 'utf8'));
33
+ } catch {
34
+ return { cases: [], palettes: [], failures: [] };
35
+ }
36
+ }
37
+
38
+ function hashSeed(value) {
39
+ let hash = 0;
40
+ const text = String(value || '');
41
+ for (let i = 0; i < text.length; i += 1) {
42
+ hash = ((hash << 5) - hash + text.charCodeAt(i)) | 0;
43
+ }
44
+ return Math.abs(hash);
45
+ }
46
+
47
+ /** Pick one structural case for the kind/subkind. */
48
+ export function selectCase({ kind = '', subkind = '', seed = '' } = {}) {
49
+ const index = loadIndex();
50
+ const cases = Array.isArray(index.cases) ? index.cases : [];
51
+ if (!cases.length) return null;
52
+ const k = String(kind || '');
53
+ const s = String(subkind || '');
54
+ let ids = [];
55
+ if (k === 'ability_name') {
56
+ if (s.includes('借火')) ids = ['boundary', 'credential', 'transaction'];
57
+ else if (s.includes('分香')) ids = ['transaction', 'ritual', 'document'];
58
+ else if (s.includes('武判')) ids = ['document', 'record'];
59
+ else if (s.includes('收愿')) ids = ['transaction', 'record'];
60
+ else if (s.includes('封炉')) ids = ['ritual', 'boundary'];
61
+ else ids = ['credential', 'document', 'boundary', 'transaction', 'ritual', 'record'];
62
+ } else if (k === 'skill_name') ids = ['ritual', 'boundary'];
63
+ else if (k === 'place_name') ids = ['boundary'];
64
+ else if (k === 'faction_name') ids = ['document', 'ritual'];
65
+ else if (k === 'item_name') ids = ['credential', 'transaction'];
66
+ else if (k === 'monster_name') ids = ['boundary', 'ritual'];
67
+ else if (k === 'world_rule') ids = ['document', 'boundary'];
68
+ else if (k === 'foreshadow') ids = ['record'];
69
+ else ids = cases.map((item) => item.id);
70
+
71
+ const wanted = ids.length ? ids : cases.map((item) => item.id);
72
+ const id = wanted[hashSeed(seed) % wanted.length];
73
+ const entry = cases.find((item) => item.id === id) || cases[0];
74
+ return { ...entry, content: readFile(path.join(MANUAL_DIR, 'cases', entry.file)) };
75
+ }
76
+
77
+ /** Pick up to `limit` genre palettes, primary genre first. */
78
+ export function selectPalettes({ genres = [], limit = 2 } = {}) {
79
+ const index = loadIndex();
80
+ const palettes = Array.isArray(index.palettes) ? index.palettes : [];
81
+ const selectedGenres = [...new Set((Array.isArray(genres) ? genres : []).map(String).filter(Boolean))];
82
+ const matched = [];
83
+ for (const genre of selectedGenres) {
84
+ for (const palette of palettes) {
85
+ if (matched.some((item) => item.id === palette.id)) continue;
86
+ if ((palette.genres || []).some((name) => genre.includes(name) || name.includes(genre))) {
87
+ matched.push({ ...palette, content: readFile(path.join(MANUAL_DIR, 'palettes', palette.file)) });
88
+ }
89
+ }
90
+ }
91
+ return matched.slice(0, Math.max(1, limit));
92
+ }
93
+
94
+ /** Pick pattern cards from the case's pattern file. */
95
+ export function selectPatterns({ caseId = '', limit = 3 } = {}) {
96
+ if (!caseId) return [];
97
+ const file = path.join(MANUAL_DIR, 'patterns', caseId + '.md');
98
+ const text = readFile(file);
99
+ if (!text) return [];
100
+ const chunks = text.split(/\n(?=##\s)/).filter(Boolean);
101
+ return chunks.slice(0, Math.max(1, limit)).map((chunk) => chunk.trim());
102
+ }
103
+
104
+ /** Pick failure cards relevant to the kind. */
105
+ export function selectFailures({ kind = '', limit = 2 } = {}) {
106
+ const naming = NAMING_KINDS.has(String(kind || ''));
107
+ const ids = naming ? ['formulaic', 'name-only'] : ['event-summary', 'naked-process'];
108
+ return ids.slice(0, Math.max(1, limit))
109
+ .map((id) => readFile(path.join(MANUAL_DIR, 'failures', id + '.md')))
110
+ .filter(Boolean);
111
+ }
112
+
113
+ /**
114
+ * Render the handbook slice for one batch.
115
+ * @param options.kind - material kind
116
+ * @param options.subkind - ability/faction subcategory
117
+ * @param options.genres - selected genres
118
+ * @param options.seed - stable batch seed for case/pattern rotation
119
+ * @param options.compact - true after the first batch to reduce prompt size
120
+ */
121
+ export function renderManualBlock({ kind = '', subkind = '', genres = [], seed = '', compact = false } = {}) {
122
+ const core = readFile(path.join(MANUAL_DIR, '00-core.md'));
123
+ const carrier = compact ? '' : readFile(path.join(MANUAL_DIR, '01-carrier.md'));
124
+ const naming = compact ? '' : readFile(path.join(MANUAL_DIR, '04-naming.md'));
125
+ const surprise = compact ? '' : readFile(path.join(MANUAL_DIR, '07-surprise.md'));
126
+ const selectedCase = selectCase({ kind, subkind, seed });
127
+ const palettes = selectPalettes({ genres, limit: compact ? 1 : 2 });
128
+ const patterns = compact ? [] : selectPatterns({ caseId: selectedCase?.id || '', limit: 3 });
129
+ const failures = selectFailures({ kind, limit: compact ? 1 : 2 });
130
+ if (!core && !selectedCase && !palettes.length) return '';
131
+
132
+ const lines = [
133
+ '# 创作手册(本批必读)',
134
+ '',
135
+ '本手册优先于旧的创作段。字段、schema、kind 硬规则、世界母体仍然优先。',
136
+ '',
137
+ ];
138
+ if (core) lines.push(core, '');
139
+ if (carrier) lines.push(carrier, '');
140
+ if (naming) lines.push(naming, '');
141
+ if (surprise) lines.push(surprise, '');
142
+ if (selectedCase?.content) {
143
+ lines.push('## 本批结构案例:' + selectedCase.id, '', selectedCase.content, '');
144
+ }
145
+ for (const palette of palettes) {
146
+ lines.push('## 题材调色板:' + palette.id, '', palette.content, '');
147
+ }
148
+ if (patterns.length) {
149
+ lines.push('## 参考模式(只学结构,不抄名字)', '');
150
+ for (const pattern of patterns) lines.push(pattern, '');
151
+ }
152
+ if (failures.length) {
153
+ lines.push('## 失败诊断(写之前先对照)', '');
154
+ for (const failure of failures) lines.push(failure, '');
155
+ }
156
+ return lines.join('\n').trim();
157
+ }
@@ -559,6 +559,10 @@ export function stylePromptBlock(styles, selected, { genres = [] } = {}) {
559
559
  lines.push('- 里世界(硬要求):');
560
560
  for (const item of asArray(rules.trace_hidden_world)) lines.push(' - ' + item);
561
561
  }
562
+ if (rules.trace_surprise) {
563
+ lines.push('- 标志性规则(硬要求):');
564
+ for (const item of asArray(rules.trace_surprise)) lines.push(' - ' + item);
565
+ }
562
566
  if (rules.tone) lines.push('- 语气:' + rules.tone);
563
567
  const preferred = asArray(style.lexicon && style.lexicon.preferred);
564
568
  const forbidden = asArray(style.lexicon && style.lexicon.forbidden);
@@ -148,6 +148,7 @@ export function generationPrompt({
148
148
  styleSummary = '',
149
149
  worldBlock = '',
150
150
  worldSummary = '',
151
+ manualBlock = '',
151
152
  subkind = '',
152
153
  groupId = '',
153
154
  worldId = '',
@@ -165,6 +166,9 @@ export function generationPrompt({
165
166
  if (styleSummary && !includeBase) {
166
167
  lines.push('## 本批风格锁定(写法层,必须保持)', '', styleSummary, '');
167
168
  }
169
+ if (manualBlock) {
170
+ lines.push(String(manualBlock).trim(), '', '---', '');
171
+ }
168
172
  lines.push('## 本次运行', '');
169
173
  lines.push('- 工作区目录:' + workspace);
170
174
  lines.push('- 目标文件(**绝对路径**):`' + target + '`');