inkbone 0.0.0-stage → 2.1.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.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +380 -0
  3. package/README.md +384 -2
  4. package/bin/inkbone.mjs +1049 -0
  5. package/configs/genres.json +591 -0
  6. package/configs/messages.json +336 -0
  7. package/configs/platforms.json +66 -0
  8. package/configs/presets.json +265 -0
  9. package/configs/severity.json +59 -0
  10. package/configs/zh-linguistics.json +1040 -0
  11. package/configs/zh-traditional.json +97 -0
  12. package/examples/claude-code-hooks.json +15 -0
  13. package/examples/mcp-config.json +12 -0
  14. package/package.json +62 -4
  15. package/prompts/00-style-architect.md +42 -0
  16. package/prompts/01-beat-planner.md +54 -0
  17. package/prompts/02-paratactic-renderer.md +63 -0
  18. package/prompts/03-targeted-rewriter.md +44 -0
  19. package/prompts/04-evidence-reviewer.md +39 -0
  20. package/prompts/05-reader-simulator.md +54 -0
  21. package/prompts/06-ledger-importer.md +41 -0
  22. package/prompts/07-chapter-settler.md +66 -0
  23. package/resources/bad_vs_good_cases.md +132 -0
  24. package/resources/eval/blind-read-instructions.md +18 -0
  25. package/resources/genre_playbooks/classical-xianxia.md +22 -0
  26. package/resources/genre_playbooks/general-clean.md +19 -0
  27. package/resources/genre_playbooks/historical-court.md +21 -0
  28. package/resources/genre_playbooks/light-fantasy.md +22 -0
  29. package/resources/genre_playbooks/mystery-thriller.md +22 -0
  30. package/resources/genre_playbooks/romance-emotional.md +20 -0
  31. package/resources/genre_playbooks/scifi-wasteland.md +21 -0
  32. package/resources/genre_playbooks/urban-realism.md +22 -0
  33. package/resources/genre_playbooks/wuxia-jianghu.md +21 -0
  34. package/resources/micro_techniques.md +77 -0
  35. package/skills/inkbone/LICENSE +21 -0
  36. package/skills/inkbone/README.md +385 -0
  37. package/skills/inkbone/SKILL.md +162 -0
  38. package/skills/inkbone/benchmarks/eval-set/README.md +49 -0
  39. package/skills/inkbone/benchmarks/eval-set/public-pairs.json +42 -0
  40. package/skills/inkbone/benchmarks/eval-set/seeds.json +42 -0
  41. package/skills/inkbone/bin/inkbone.mjs +1049 -0
  42. package/skills/inkbone/configs/genres.json +591 -0
  43. package/skills/inkbone/configs/messages.json +336 -0
  44. package/skills/inkbone/configs/platforms.json +66 -0
  45. package/skills/inkbone/configs/presets.json +265 -0
  46. package/skills/inkbone/configs/severity.json +59 -0
  47. package/skills/inkbone/configs/zh-linguistics.json +1040 -0
  48. package/skills/inkbone/configs/zh-traditional.json +97 -0
  49. package/skills/inkbone/package.json +64 -0
  50. package/skills/inkbone/prompts/00-style-architect.md +42 -0
  51. package/skills/inkbone/prompts/01-beat-planner.md +54 -0
  52. package/skills/inkbone/prompts/02-paratactic-renderer.md +63 -0
  53. package/skills/inkbone/prompts/03-targeted-rewriter.md +44 -0
  54. package/skills/inkbone/prompts/04-evidence-reviewer.md +39 -0
  55. package/skills/inkbone/prompts/05-reader-simulator.md +54 -0
  56. package/skills/inkbone/prompts/06-ledger-importer.md +41 -0
  57. package/skills/inkbone/prompts/07-chapter-settler.md +66 -0
  58. package/skills/inkbone/resources/bad_vs_good_cases.md +132 -0
  59. package/skills/inkbone/resources/eval/blind-read-instructions.md +18 -0
  60. package/skills/inkbone/resources/genre_playbooks/classical-xianxia.md +22 -0
  61. package/skills/inkbone/resources/genre_playbooks/general-clean.md +19 -0
  62. package/skills/inkbone/resources/genre_playbooks/historical-court.md +21 -0
  63. package/skills/inkbone/resources/genre_playbooks/light-fantasy.md +22 -0
  64. package/skills/inkbone/resources/genre_playbooks/mystery-thriller.md +22 -0
  65. package/skills/inkbone/resources/genre_playbooks/romance-emotional.md +20 -0
  66. package/skills/inkbone/resources/genre_playbooks/scifi-wasteland.md +21 -0
  67. package/skills/inkbone/resources/genre_playbooks/urban-realism.md +22 -0
  68. package/skills/inkbone/resources/genre_playbooks/wuxia-jianghu.md +21 -0
  69. package/skills/inkbone/resources/micro_techniques.md +77 -0
  70. package/skills/inkbone/src/aigc-guard.mjs +83 -0
  71. package/skills/inkbone/src/auditor.mjs +24 -0
  72. package/skills/inkbone/src/benchmark-runner.mjs +71 -0
  73. package/skills/inkbone/src/boundary-compiler.mjs +60 -0
  74. package/skills/inkbone/src/browser-doctor.mjs +30 -0
  75. package/skills/inkbone/src/calibrator.mjs +175 -0
  76. package/skills/inkbone/src/config-loader.mjs +233 -0
  77. package/skills/inkbone/src/continuity.mjs +5 -0
  78. package/skills/inkbone/src/core/aigc-guard.mjs +387 -0
  79. package/skills/inkbone/src/core/auditor.mjs +1074 -0
  80. package/skills/inkbone/src/core/boundary-compiler.mjs +526 -0
  81. package/skills/inkbone/src/core/browser-doctor.mjs +320 -0
  82. package/skills/inkbone/src/core/config-compiler.mjs +434 -0
  83. package/skills/inkbone/src/core/continuity.mjs +158 -0
  84. package/skills/inkbone/src/core/evidence-validator.mjs +77 -0
  85. package/skills/inkbone/src/core/exporter.mjs +423 -0
  86. package/skills/inkbone/src/core/formatter.mjs +241 -0
  87. package/skills/inkbone/src/core/ledger-manager.mjs +843 -0
  88. package/skills/inkbone/src/core/normalizer.mjs +517 -0
  89. package/skills/inkbone/src/core/profiler.mjs +686 -0
  90. package/skills/inkbone/src/core/rule-engine.mjs +1710 -0
  91. package/skills/inkbone/src/core/style-profiler.mjs +229 -0
  92. package/skills/inkbone/src/detector.mjs +270 -0
  93. package/skills/inkbone/src/doctor.mjs +430 -0
  94. package/skills/inkbone/src/evaluation.mjs +311 -0
  95. package/skills/inkbone/src/evidence-validator.mjs +15 -0
  96. package/skills/inkbone/src/exporter.mjs +142 -0
  97. package/skills/inkbone/src/formatter.mjs +34 -0
  98. package/skills/inkbone/src/importer.mjs +230 -0
  99. package/skills/inkbone/src/index.mjs +134 -0
  100. package/skills/inkbone/src/ledger-manager.mjs +22 -0
  101. package/skills/inkbone/src/mcp-server.mjs +950 -0
  102. package/skills/inkbone/src/normalizer.mjs +73 -0
  103. package/skills/inkbone/src/profiler.mjs +17 -0
  104. package/skills/inkbone/src/rule-engine.mjs +91 -0
  105. package/skills/inkbone/src/rule-stats.mjs +142 -0
  106. package/skills/inkbone/src/style-profiler.mjs +25 -0
  107. package/src/aigc-guard.mjs +83 -0
  108. package/src/auditor.mjs +24 -0
  109. package/src/benchmark-runner.mjs +71 -0
  110. package/src/boundary-compiler.mjs +60 -0
  111. package/src/browser-doctor.mjs +30 -0
  112. package/src/calibrator.mjs +175 -0
  113. package/src/config-loader.mjs +233 -0
  114. package/src/continuity.mjs +5 -0
  115. package/src/core/aigc-guard.mjs +387 -0
  116. package/src/core/auditor.mjs +1074 -0
  117. package/src/core/boundary-compiler.mjs +526 -0
  118. package/src/core/browser-doctor.mjs +320 -0
  119. package/src/core/config-compiler.mjs +434 -0
  120. package/src/core/continuity.mjs +158 -0
  121. package/src/core/evidence-validator.mjs +77 -0
  122. package/src/core/exporter.mjs +423 -0
  123. package/src/core/formatter.mjs +241 -0
  124. package/src/core/ledger-manager.mjs +843 -0
  125. package/src/core/normalizer.mjs +517 -0
  126. package/src/core/profiler.mjs +686 -0
  127. package/src/core/rule-engine.mjs +1710 -0
  128. package/src/core/style-profiler.mjs +229 -0
  129. package/src/detector.mjs +270 -0
  130. package/src/doctor.mjs +430 -0
  131. package/src/evaluation.mjs +311 -0
  132. package/src/evidence-validator.mjs +15 -0
  133. package/src/exporter.mjs +142 -0
  134. package/src/formatter.mjs +34 -0
  135. package/src/importer.mjs +230 -0
  136. package/src/index.mjs +134 -0
  137. package/src/ledger-manager.mjs +22 -0
  138. package/src/mcp-server.mjs +950 -0
  139. package/src/normalizer.mjs +73 -0
  140. package/src/profiler.mjs +17 -0
  141. package/src/rule-engine.mjs +91 -0
  142. package/src/rule-stats.mjs +142 -0
  143. package/src/style-profiler.mjs +25 -0
package/src/doctor.mjs ADDED
@@ -0,0 +1,430 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import {
4
+ loadGenresConfig,
5
+ loadLinguisticsConfig,
6
+ resolveGenre,
7
+ } from "./config-loader.mjs";
8
+ import { auditChapterText } from "./auditor.mjs";
9
+ import { collectTextFiles } from "./calibrator.mjs";
10
+ import { parseChapterNumberAndTitle } from "./importer.mjs";
11
+ import { collectCharacterNames } from "./continuity.mjs";
12
+ import { formatDoctorMarkdown as formatDoctorMarkdownLocalized } from "./formatter.mjs";
13
+
14
+ // 列出所有内置题材语域包及其默认预设配置摘要
15
+ export function listGenres(customGenresPath = null) {
16
+ const cfg = loadGenresConfig(customGenresPath);
17
+ return Object.values(cfg.genres).map((g) => ({
18
+ id: g.id,
19
+ title: g.title,
20
+ defaultPreset: g.defaultPreset,
21
+ registerFormula: g.registerFormula,
22
+ ruleCount: g.compiledRegisterRules.length,
23
+ }));
24
+ }
25
+
26
+ // 根据大纲、设定集或章节文本中的领域信号词自动推断最佳题材语域包
27
+ export function inferGenreFromTexts(texts, customGenresPath = null) {
28
+ const cfg = loadGenresConfig(customGenresPath);
29
+ const combined = (texts || []).join("\n");
30
+ let bestId = cfg.defaultGenre;
31
+ let bestScore = 0;
32
+ let bestSignals = [];
33
+
34
+ for (const [id, pack] of Object.entries(cfg.genres)) {
35
+ const signals = pack.domainSignals || [];
36
+ if (signals.length === 0) continue;
37
+
38
+ const matched = [];
39
+ let totalHits = 0;
40
+ for (const sig of signals) {
41
+ const parts = combined.split(sig);
42
+ const count = parts.length - 1;
43
+ if (count > 0) {
44
+ matched.push({ term: sig, count });
45
+ totalHits += count;
46
+ }
47
+ }
48
+
49
+ // 要求至少命中两个不同的领域特征词以防止单点误判
50
+ if (matched.length >= 2) {
51
+ const score = matched.length * 10 + Math.min(totalHits, 60);
52
+ if (score > bestScore) {
53
+ bestScore = score;
54
+ bestId = id;
55
+ bestSignals = matched.sort((a, b) => b.count - a.count);
56
+ }
57
+ }
58
+ }
59
+
60
+ const chosen = cfg.genres[bestId];
61
+ return {
62
+ genreId: chosen.id,
63
+ title: chosen.title,
64
+ defaultPreset: chosen.defaultPreset,
65
+ autoDetected: bestScore > 0,
66
+ matchedSignalCount: bestSignals.length,
67
+ matchedSignals: bestSignals.slice(0, 8),
68
+ registerFormula: chosen.registerFormula,
69
+ voiceMatrix: chosen.voiceMatrix,
70
+ };
71
+ }
72
+
73
+ // 从章首标题或文件名解析数字/中文数字章节号,并与台账目录核对匹配
74
+ function resolveDoctorChapterInfo(filePath, rawContent, ledger, lingConfig) {
75
+ const parsed = parseChapterNumberAndTitle(filePath, rawContent, lingConfig);
76
+ let detectedNumber = parsed.chapterNumber;
77
+ if (detectedNumber === null) {
78
+ const base = path.basename(filePath);
79
+ const m = base.match(/(\d{1,4})/u);
80
+ if (m) detectedNumber = Number(m[1]);
81
+ }
82
+ let ledgerChapterNumber = null;
83
+ if (
84
+ detectedNumber !== null &&
85
+ ledger &&
86
+ Array.isArray(ledger.chapters) &&
87
+ ledger.chapters.some((c) => Number(c.chapterNumber) === detectedNumber)
88
+ ) {
89
+ ledgerChapterNumber = detectedNumber;
90
+ }
91
+ return { detectedNumber, ledgerChapterNumber };
92
+ }
93
+
94
+ // 解析章节范围过滤表达式(例如 "40-45,48")为数字集合
95
+ export function parseChapterFilterSpec(spec) {
96
+ if (!spec) return null;
97
+ if (spec instanceof Set) return spec;
98
+ const set = new Set();
99
+ const tokens = String(spec)
100
+ .split(/[,;\s]+/u)
101
+ .map((s) => s.trim())
102
+ .filter(Boolean);
103
+ for (const token of tokens) {
104
+ const rangeMatch = token.match(/^(\d+)\s*-\s*(\d+)$/u);
105
+ if (rangeMatch) {
106
+ const start = Number(rangeMatch[1]);
107
+ const end = Number(rangeMatch[2]);
108
+ const lo = Math.min(start, end);
109
+ const hi = Math.max(start, end);
110
+ for (let n = lo; n <= hi; n += 1) set.add(n);
111
+ } else if (/^\d+$/u.test(token)) {
112
+ set.add(Number(token));
113
+ }
114
+ }
115
+ return set.size > 0 ? set : null;
116
+ }
117
+
118
+ // 对单章或整书目录执行四维体检(支持 --chapters / --changed 增量过滤同时保留前章回声检查)
119
+ export function diagnoseProject(targetPaths, options = {}) {
120
+ const chapterFiles = collectTextFiles([].concat(targetPaths || []));
121
+ if (chapterFiles.length === 0) {
122
+ throw new Error("No .md or .txt files found in target paths for doctor.");
123
+ }
124
+
125
+ const lingConfig = options.linguisticsConfig || loadLinguisticsConfig();
126
+ const outlineFiles = collectTextFiles([].concat(options.outlinePaths || []));
127
+ const rawEntries = chapterFiles.map((filePath, idx) => {
128
+ const text = fs.readFileSync(filePath, "utf8");
129
+ const info = resolveDoctorChapterInfo(
130
+ filePath,
131
+ text,
132
+ options.ledger,
133
+ lingConfig
134
+ );
135
+ return { idx, filePath, text, info };
136
+ });
137
+ // 按解析出的章节号排序,避免中文卷名(如第一卷/第三卷/第二卷)字典序打乱相邻章衔接
138
+ rawEntries.sort((a, b) => {
139
+ const numA = a.info.detectedNumber ?? Number.MAX_SAFE_INTEGER;
140
+ const numB = b.info.detectedNumber ?? Number.MAX_SAFE_INTEGER;
141
+ return numA - numB || a.idx - b.idx;
142
+ });
143
+ const sortedFiles = rawEntries.map((e) => e.filePath);
144
+ const chapterTexts = rawEntries.map((e) => e.text);
145
+ const chapInfos = rawEntries.map((e) => e.info);
146
+ const outlineTexts = outlineFiles.map((f) => fs.readFileSync(f, "utf8"));
147
+
148
+ const inferred = options.genre
149
+ ? { genreId: options.genre, matchedSignals: [] }
150
+ : inferGenreFromTexts(
151
+ [...outlineTexts, ...chapterTexts.slice(0, 5)],
152
+ options.genresPath
153
+ );
154
+ const genrePack = options.genre
155
+ ? resolveGenre(options.genre, options.genresPath)
156
+ : resolveGenre(inferred.genreId, options.genresPath);
157
+
158
+ // 未显式指定或从项目配置读取题材时,顺手检查目录内是否存在明确匹配到其他题材的章稿
159
+ const mixedGenreFiles = [];
160
+ if (!options.genre && sortedFiles.length > 1) {
161
+ for (let idx = 0; idx < sortedFiles.length; idx += 1) {
162
+ const single = inferGenreFromTexts([chapterTexts[idx]], options.genresPath);
163
+ if (single.autoDetected && single.genreId !== genrePack.id) {
164
+ mixedGenreFiles.push({
165
+ file: path.basename(sortedFiles[idx]),
166
+ inferredGenre: single.genreId,
167
+ matchedSignals: single.matchedSignals.slice(0, 4).map((s) => s.term),
168
+ });
169
+ }
170
+ }
171
+ }
172
+
173
+ // 支持按章节号范围(chapterFilter)或变动文件集合(changedFiles)做增量体检,但保留前章文本用于跨章回声检测
174
+ const chapterFilterSet = parseChapterFilterSpec(options.chapterFilter);
175
+ const changedFileSet =
176
+ Array.isArray(options.changedFiles) && options.changedFiles.length > 0
177
+ ? new Set(options.changedFiles.map((p) => path.resolve(p)))
178
+ : null;
179
+ const incrementalActive = Boolean(chapterFilterSet || changedFileSet);
180
+ const incrementalMode = chapterFilterSet
181
+ ? changedFileSet
182
+ ? "chapters+changed"
183
+ : "chapters"
184
+ : changedFileSet
185
+ ? "changed"
186
+ : "full";
187
+
188
+ const selectedIndices = [];
189
+ for (let idx = 0; idx < sortedFiles.length; idx += 1) {
190
+ if (!incrementalActive) {
191
+ selectedIndices.push(idx);
192
+ continue;
193
+ }
194
+ const info = chapInfos[idx];
195
+ const absFile = path.resolve(sortedFiles[idx]);
196
+ const matchChapter =
197
+ !chapterFilterSet ||
198
+ (info.detectedNumber !== null && chapterFilterSet.has(info.detectedNumber));
199
+ const matchChanged = !changedFileSet || changedFileSet.has(absFile);
200
+ if (matchChapter && matchChanged) {
201
+ selectedIndices.push(idx);
202
+ }
203
+ }
204
+
205
+ const totals = {
206
+ chaptersScanned: selectedIndices.length,
207
+ hardErrors: 0,
208
+ registerCollisions: 0,
209
+ narrativeFillers: 0,
210
+ aiCliches: 0,
211
+ rhetoricalPatterns: 0,
212
+ densityTics: 0,
213
+ degenerationErrors: 0,
214
+ metaLeaks: 0,
215
+ pronounStreaks: 0,
216
+ totalWarnings: 0,
217
+ };
218
+
219
+ const chapters = selectedIndices.map((idx) => {
220
+ const filePath = sortedFiles[idx];
221
+ const raw = chapterTexts[idx];
222
+ const info = chapInfos[idx];
223
+ const chapNum =
224
+ sortedFiles.length === 1 && options.chapterNumber
225
+ ? Number(options.chapterNumber)
226
+ : info.ledgerChapterNumber;
227
+ const prevInfo = idx > 0 ? chapInfos[idx - 1] : null;
228
+ const prevText =
229
+ idx > 0 &&
230
+ info.detectedNumber !== null &&
231
+ prevInfo?.detectedNumber === info.detectedNumber - 1
232
+ ? chapterTexts[idx - 1]
233
+ : "";
234
+
235
+ const audit = auditChapterText(raw, {
236
+ genre: genrePack.id,
237
+ presetName: options.presetName || genrePack.defaultPreset,
238
+ customGates: options.customGates || null,
239
+ variant: options.variant || "auto",
240
+ ledger: options.ledger || null,
241
+ chapterNumber: chapNum,
242
+ previousChapterText: prevText,
243
+ skipLengthGate: Boolean(options.skipLengthGate),
244
+ aigcGuard: Boolean(options.aigcGuard),
245
+ aigcThreshold: options.aigcThreshold,
246
+ genresPath: options.genresPath,
247
+ presetsPath: options.presetsPath,
248
+ linguisticsConfig: lingConfig,
249
+ projectRules: options.projectRules || null,
250
+ });
251
+
252
+ const regV = audit.violations.find((v) => v.code === "REGISTER_COLLISION");
253
+ const filV = audit.violations.find((v) => v.code === "NARRATIVE_FILLER");
254
+ const cliV = audit.violations.find((v) => v.code === "FORBIDDEN_AI_CLICHE");
255
+ const rhetV = audit.violations.find((v) => v.code === "RHETORICAL_AI_PATTERN");
256
+ const ticV = audit.violations.find((v) => v.code === "PROSE_DENSITY_TIC");
257
+ const degV = audit.violations.find((v) => v.code === "DEGENERATION_DETECTED");
258
+ const metaV = audit.violations.find((v) => v.code === "ENGINEERING_META_LEAK");
259
+ const proV = audit.violations.find((v) => v.code === "PRONOUN_HEAD_STREAK");
260
+
261
+ const regCount = regV ? regV.count : 0;
262
+ const filCount = filV ? filV.count : 0;
263
+ const cliCount = cliV ? cliV.count : 0;
264
+ const rhetCount = rhetV ? rhetV.count : 0;
265
+ const ticCount = ticV ? ticV.count : 0;
266
+ const degCount = degV ? degV.count : 0;
267
+ const metaCount = metaV ? metaV.count : 0;
268
+ const proSpans = proV ? proV.spans.length : 0;
269
+
270
+ totals.hardErrors += audit.summary.error;
271
+ totals.registerCollisions += regCount;
272
+ totals.narrativeFillers += filCount;
273
+ totals.aiCliches += cliCount;
274
+ totals.rhetoricalPatterns += rhetCount;
275
+ totals.densityTics += ticCount;
276
+ totals.degenerationErrors += degCount;
277
+ totals.metaLeaks += metaCount;
278
+ totals.pronounStreaks += proSpans;
279
+ totals.totalWarnings += audit.summary.warning;
280
+
281
+ return {
282
+ file: path.basename(filePath),
283
+ path: filePath,
284
+ chapterNumber: chapNum,
285
+ detectedChapterNumber: info.detectedNumber,
286
+ pass: audit.pass,
287
+ totalHan: audit.metrics.totalHan,
288
+ maxPronounHeadStreak: audit.metrics.maxPronounHeadStreak,
289
+ summary: audit.summary,
290
+ counts: {
291
+ registerCollisions: regCount,
292
+ narrativeFillers: filCount,
293
+ aiCliches: cliCount,
294
+ rhetoricalPatterns: rhetCount,
295
+ densityTics: ticCount,
296
+ degenerationErrors: degCount,
297
+ metaLeaks: metaCount,
298
+ pronounStreakSpans: proSpans,
299
+ },
300
+ violations: audit.violations.filter((v) => v.severity !== "info"),
301
+ surgeryTargets: audit.surgeryTargets,
302
+ };
303
+ });
304
+
305
+ const { names: detectedCharacterNames } = collectCharacterNames(
306
+ options.ledger,
307
+ options.characterNames || []
308
+ );
309
+ const hints = [];
310
+ if (detectedCharacterNames.length === 0) {
311
+ hints.push({
312
+ code: "SUBJECT_CONTINUITY_DISABLED",
313
+ detail:
314
+ "No characterNames configured; SUBJECT_AMBIGUITY checks were skipped. Populate ledger.characterNames or run import-ledger --auto-characters.",
315
+ });
316
+ }
317
+
318
+ return {
319
+ pass: totals.hardErrors === 0,
320
+ genre: {
321
+ id: genrePack.id,
322
+ title: genrePack.title,
323
+ source:
324
+ options.genreSource ||
325
+ (options.genre ? "explicit" : inferred.autoDetected ? "inferred" : "default"),
326
+ matchedSignals: inferred.matchedSignals,
327
+ mixedGenreFiles,
328
+ defaultPreset: genrePack.defaultPreset,
329
+ registerFormula: genrePack.registerFormula,
330
+ voiceMatrix: genrePack.voiceMatrix,
331
+ },
332
+ hints,
333
+ incremental: {
334
+ active: incrementalActive,
335
+ mode: incrementalMode,
336
+ scannedCount: selectedIndices.length,
337
+ totalDiscovered: sortedFiles.length,
338
+ },
339
+ totals,
340
+ chapters,
341
+ };
342
+ }
343
+
344
+ // 将四维体检报告格式化为简洁易读的 Markdown 概览与行级手术单(支持 lang: "zh" | "en",默认中文)
345
+ export function formatDoctorMarkdown(diagnosis, options = {}) {
346
+ return formatDoctorMarkdownLocalized(diagnosis, options);
347
+ }
348
+
349
+ // 初始化新小说工程的通用配置与空白防吃书台账骨架
350
+ export function scaffoldProject(targetDir, options = {}) {
351
+ const absDir = path.resolve(targetDir || ".");
352
+ const genrePack = resolveGenre(options.genre || "general-clean", options.genresPath);
353
+ const title = options.title || path.basename(absDir) || "Untitled-Novel";
354
+ const force = Boolean(options.force);
355
+
356
+ fs.mkdirSync(absDir, { recursive: true });
357
+
358
+ const novelConfigPath = path.resolve(absDir, "novel.json");
359
+ const ledgerPath = path.resolve(absDir, "ledger.json");
360
+ const created = [];
361
+ const skipped = [];
362
+
363
+ const novelConfig = {
364
+ projectTitle: title,
365
+ genre: genrePack.id,
366
+ preset: options.presetName || genrePack.defaultPreset,
367
+ registerFormula: genrePack.registerFormula,
368
+ voiceMatrix: genrePack.voiceMatrix,
369
+ ledgerFile: "./ledger.json",
370
+ projectRules: {
371
+ clicheRules: [],
372
+ fillerRules: [],
373
+ registerRules: [],
374
+ symmetricSkeletons: [],
375
+ rhetoricalRules: [],
376
+ disabledRuleIds: [],
377
+ whitelistLiterals: [],
378
+ },
379
+ };
380
+
381
+ const starterLedger = {
382
+ projectTitle: title,
383
+ protagonist: {
384
+ name: "PROTAGONIST_NAME",
385
+ role: "PROTAGONIST_OCCUPATION_AND_ORIGIN",
386
+ initialState: "SURFACE_VS_ACTUAL_STATE",
387
+ coreEdge: "UNIQUE_MECHANISM_AND_HARD_COST",
388
+ },
389
+ deprecatedTerms: [],
390
+ characterNames: [],
391
+ immutableWorldRules: [
392
+ "Define hard cost/limit of the core mechanism here.",
393
+ "Define irreversible power/social hierarchy threshold here.",
394
+ ],
395
+ knowledgeLedger: [],
396
+ characterSnapshots: {},
397
+ foreshadowing: [],
398
+ chapters: [
399
+ {
400
+ chapterNumber: 1,
401
+ title: "CHAPTER_1_TITLE",
402
+ coreSummary: "Immediate anomaly/crisis + concrete stakes + hook.",
403
+ requiredAnchors: [],
404
+ futureForbiddenTerms: [],
405
+ },
406
+ ],
407
+ };
408
+
409
+ if (!fs.existsSync(novelConfigPath) || force) {
410
+ fs.writeFileSync(novelConfigPath, JSON.stringify(novelConfig, null, 2) + "\n");
411
+ created.push(novelConfigPath);
412
+ } else {
413
+ skipped.push(novelConfigPath);
414
+ }
415
+
416
+ if (!fs.existsSync(ledgerPath) || force) {
417
+ fs.writeFileSync(ledgerPath, JSON.stringify(starterLedger, null, 2) + "\n");
418
+ created.push(ledgerPath);
419
+ } else {
420
+ skipped.push(ledgerPath);
421
+ }
422
+
423
+ return {
424
+ targetDir: absDir,
425
+ genre: genrePack.id,
426
+ preset: novelConfig.preset,
427
+ created,
428
+ skipped,
429
+ };
430
+ }