@cloud411716/fancy-webnovel 4.30.13 → 4.30.14

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 (33) hide show
  1. package/docs/material-library/manual/00-core.md +67 -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/cases/boundary.md +38 -0
  9. package/docs/material-library/manual/cases/credential.md +38 -0
  10. package/docs/material-library/manual/cases/document.md +32 -0
  11. package/docs/material-library/manual/cases/record.md +38 -0
  12. package/docs/material-library/manual/cases/ritual.md +32 -0
  13. package/docs/material-library/manual/cases/transaction.md +32 -0
  14. package/docs/material-library/manual/failures/event-summary.md +30 -0
  15. package/docs/material-library/manual/failures/formulaic.md +30 -0
  16. package/docs/material-library/manual/failures/naked-process.md +34 -0
  17. package/docs/material-library/manual/failures/name-only.md +33 -0
  18. package/docs/material-library/manual/index.json +205 -0
  19. package/docs/material-library/manual/palettes/scifi.md +27 -0
  20. package/docs/material-library/manual/palettes/suspense.md +27 -0
  21. package/docs/material-library/manual/palettes/urban.md +27 -0
  22. package/docs/material-library/manual/palettes/western-fantasy.md +27 -0
  23. package/docs/material-library/manual/palettes/xianxia.md +27 -0
  24. package/docs/material-library/manual/patterns/boundary.md +29 -0
  25. package/docs/material-library/manual/patterns/credential.md +29 -0
  26. package/docs/material-library/manual/patterns/document.md +29 -0
  27. package/docs/material-library/manual/patterns/record.md +29 -0
  28. package/docs/material-library/manual/patterns/ritual.md +29 -0
  29. package/docs/material-library/manual/patterns/transaction.md +29 -0
  30. package/package.json +1 -1
  31. package/plugins/fancy-material/index.js +11 -0
  32. package/plugins/fancy-material/manual.js +155 -0
  33. package/plugins/fancy-material/templates.js +4 -0
@@ -0,0 +1,155 @@
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 selectedCase = selectCase({ kind, subkind, seed });
126
+ const palettes = selectPalettes({ genres, limit: compact ? 1 : 2 });
127
+ const patterns = compact ? [] : selectPatterns({ caseId: selectedCase?.id || '', limit: 3 });
128
+ const failures = selectFailures({ kind, limit: compact ? 1 : 2 });
129
+ if (!core && !selectedCase && !palettes.length) return '';
130
+
131
+ const lines = [
132
+ '# 创作手册(本批必读)',
133
+ '',
134
+ '本手册优先于旧的创作段。字段、schema、kind 硬规则、世界母体仍然优先。',
135
+ '',
136
+ ];
137
+ if (core) lines.push(core, '');
138
+ if (carrier) lines.push(carrier, '');
139
+ if (naming) lines.push(naming, '');
140
+ if (selectedCase?.content) {
141
+ lines.push('## 本批结构案例:' + selectedCase.id, '', selectedCase.content, '');
142
+ }
143
+ for (const palette of palettes) {
144
+ lines.push('## 题材调色板:' + palette.id, '', palette.content, '');
145
+ }
146
+ if (patterns.length) {
147
+ lines.push('## 参考模式(只学结构,不抄名字)', '');
148
+ for (const pattern of patterns) lines.push(pattern, '');
149
+ }
150
+ if (failures.length) {
151
+ lines.push('## 失败诊断(写之前先对照)', '');
152
+ for (const failure of failures) lines.push(failure, '');
153
+ }
154
+ return lines.join('\n').trim();
155
+ }
@@ -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 + '`');