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
@@ -0,0 +1,1074 @@
1
+ import {
2
+ resolveGenreFromConfig,
3
+ resolvePresetFromConfig,
4
+ detectScriptVariant,
5
+ } from "./config-compiler.mjs";
6
+
7
+ // 对照 calibrate 生成的人类参考区间,列出每项指标的位置
8
+ function compareWithReference(metrics, reference) {
9
+ const rows = [];
10
+ for (const [key, stat] of Object.entries(reference.metrics || {})) {
11
+ const actual = metrics[key];
12
+ if (typeof actual !== "number") continue;
13
+ let position = "inside";
14
+ if (actual < stat.p10) position = "below_p10";
15
+ else if (actual > stat.p90) position = "above_p90";
16
+ rows.push({ metric: key, actual, p10: stat.p10, median: stat.median, p90: stat.p90, position });
17
+ }
18
+ return {
19
+ sampleCount: reference.sampleCount,
20
+ reliable: Boolean(reference.reliable),
21
+ outside: rows.filter((r) => r.position !== "inside"),
22
+ rows,
23
+ };
24
+ }
25
+ import { profileText } from "./profiler.mjs";
26
+ import { collectCharacterNames, scanSubjectContinuity } from "./continuity.mjs";
27
+ import {
28
+ verifyChapterBoundaries,
29
+ computeBoundaryEchoRatio,
30
+ } from "./boundary-compiler.mjs";
31
+ import {
32
+ scanParagraphRuleSet,
33
+ evaluateHitsWithDensity,
34
+ scanCrossParagraphParallel,
35
+ runDensityTics,
36
+ runDegenerationChecks,
37
+ checkOutlineCopy,
38
+ checkCharCountClaims,
39
+ checkCalendarSpanContradictions,
40
+ checkGoldenOpeningPacing,
41
+ } from "./rule-engine.mjs";
42
+ import { scanChapterAigcWindows } from "./aigc-guard.mjs";
43
+
44
+ // 统计命中列表里指定 family 的总次数(用于跨规则家族联合密度升级)
45
+ function countRuleFamily(hits, rules) {
46
+ const familyById = new Map();
47
+ for (const r of rules || []) {
48
+ if (r && r.id && r.family) familyById.set(r.id, r.family);
49
+ }
50
+ const counts = new Map();
51
+ for (const h of hits || []) {
52
+ const fam = h.family || familyById.get(h.id);
53
+ if (fam) counts.set(fam, (counts.get(fam) || 0) + 1);
54
+ }
55
+ return counts;
56
+ }
57
+
58
+ // 针对输入文本执行预设门禁与题材语域审计,并生成段落级靶向手术指令单
59
+ export function auditChapterText(rawContent, options = {}) {
60
+ const lingConfig = options.linguisticsConfig;
61
+ const genresConfig = options.genresConfig;
62
+ const presetsConfig = options.presetsConfig;
63
+ const severity = options.severityConfig;
64
+ if (!lingConfig || !genresConfig || !presetsConfig || !severity) {
65
+ throw new Error(
66
+ "linguisticsConfig, genresConfig, presetsConfig, and severityConfig are required in core auditor."
67
+ );
68
+ }
69
+ const genrePack = options.genre
70
+ ? resolveGenreFromConfig(genresConfig, options.genre)
71
+ : null;
72
+ const effectivePresetName =
73
+ options.presetName || (genrePack ? genrePack.defaultPreset : null);
74
+ const preset = resolvePresetFromConfig(presetsConfig, effectivePresetName);
75
+ const gates =
76
+ options.customGates && typeof options.customGates === "object"
77
+ ? { ...preset.gates, ...options.customGates }
78
+ : preset.gates;
79
+
80
+ // 解析简繁语体变体(auto 自动检测;仅在识别为繁体或显式指定 zh-hant 时叠加繁体规则层)
81
+ const tradCfg = options.traditionalConfig || null;
82
+ const requestedVariant = options.variant || "auto";
83
+ const scriptVariant =
84
+ requestedVariant === "zh-hant"
85
+ ? "zh-hant"
86
+ : requestedVariant === "zh-hans"
87
+ ? "zh-hans"
88
+ : tradCfg
89
+ ? detectScriptVariant(rawContent, tradCfg)
90
+ : "zh-hans";
91
+ const useTraditional = scriptVariant === "zh-hant" && Boolean(tradCfg);
92
+
93
+ // 三层规则合并:通用层(+可选繁体层) → 题材包 → 书目录项目规则;项目可用 disabledRuleIds 关掉上层规则
94
+ const project = options.projectRules || null;
95
+ const disabled = project ? project.disabledRuleIds : new Set();
96
+ const whitelistLiterals = project?.whitelistLiterals || [];
97
+ const enabled = (rules) => (rules || []).filter((rule) => !disabled.has(rule.id));
98
+ const clicheRules = enabled([
99
+ ...lingConfig.compiledRegex.forbiddenCliches,
100
+ ...(useTraditional ? tradCfg.compiledClicheRules : []),
101
+ ...(genrePack ? genrePack.compiledClicheRules : []),
102
+ ...(project ? project.clicheRules : []),
103
+ ]);
104
+ const symmetricRules = enabled([
105
+ ...lingConfig.compiledRegex.symmetricSkeletons,
106
+ ...(project ? project.symmetricSkeletons : []),
107
+ ]);
108
+ const registerRules = enabled([
109
+ ...(useTraditional ? tradCfg.compiledRegisterRules : []),
110
+ ...(genrePack ? genrePack.compiledRegisterRules : []),
111
+ ...(project ? project.registerRules : []),
112
+ ]);
113
+ const fillerRules = enabled([
114
+ ...genresConfig.compiledUniversalFillers,
115
+ ...(useTraditional ? tradCfg.compiledFillerRules : []),
116
+ ...(genrePack ? genrePack.compiledFillerRules : []),
117
+ ...(project ? project.fillerRules : []),
118
+ ]);
119
+ const rhetoricalRules = enabled([
120
+ ...(lingConfig.compiledRegex.rhetoricalRules || []),
121
+ ...(genrePack ? genrePack.compiledRhetoricalRules || [] : []),
122
+ ...(project ? project.rhetoricalRules || [] : []),
123
+ ]);
124
+ const dialogueHygieneRules = enabled([
125
+ ...(lingConfig.compiledRegex.dialogueHygieneRules || []),
126
+ ...(useTraditional ? tradCfg.compiledDialogueHygieneRules : []),
127
+ ]);
128
+
129
+ const profile = profileText(rawContent, lingConfig, {
130
+ forbiddenCliches: clicheRules,
131
+ symmetricSkeletons: symmetricRules,
132
+ whitelistLiterals,
133
+ });
134
+ const m = profile.metrics;
135
+ const d = profile.diagnostics;
136
+
137
+ const scanOpts = {
138
+ totalHan: m.totalHan,
139
+ quoteMaskRegexes: lingConfig.compiledRegex.quoteMaskRegexes || [],
140
+ quoteMaskChar: lingConfig.tokens.quoteMaskChar || lingConfig.tokens.questionMark || "?",
141
+ whitelistLiterals,
142
+ whitelistMaskChar: lingConfig.tokens.whitelistMaskChar || " ",
143
+ visibleCharRegex:
144
+ lingConfig.compiledRegex.visibleCharGlobal ||
145
+ lingConfig.compiledRegex.hanCharGlobal,
146
+ tailWindowChars:
147
+ lingConfig.compiledRegex.densityRules?.tailWindowChars || 600,
148
+ };
149
+
150
+ const violations = [];
151
+
152
+ // 0a. 扫描所选题材语域防火墙规则(默认扫描全段含对白,支持白名单、密度与必改分级)
153
+ const rawRegisterHits = scanParagraphRuleSet(d.paragraphs, registerRules, scanOpts);
154
+ const regEval = evaluateHitsWithDensity(rawRegisterHits, registerRules, m.totalHan);
155
+ const registerHits = regEval.hits;
156
+ if (registerHits.length > 0) {
157
+ violations.push({
158
+ code: "REGISTER_COLLISION",
159
+ genre: genrePack ? genrePack.id : null,
160
+ count: registerHits.length,
161
+ hits: registerHits,
162
+ forceSeverity: regEval.hasBlocking ? "error" : undefined,
163
+ remedy:
164
+ "Purge out-of-register dialect, storyteller cliches, or period anachronisms to keep narrative voice pure.",
165
+ });
166
+ }
167
+
168
+ // 0b. 扫描跨题材通用无效穿插水词(送客寒暄、目的解释尾巴、说书人感叹与过桥胶水词)
169
+ const rawFillerHits = scanParagraphRuleSet(d.paragraphs, fillerRules, scanOpts);
170
+ const fillerEval = evaluateHitsWithDensity(rawFillerHits, fillerRules, m.totalHan);
171
+ const fillerHits = fillerEval.hits;
172
+ if (fillerHits.length > 0) {
173
+ violations.push({
174
+ code: "NARRATIVE_FILLER",
175
+ count: fillerHits.length,
176
+ hits: fillerHits,
177
+ forceSeverity: fillerEval.hasBlocking ? "error" : undefined,
178
+ remedy:
179
+ "Apply Late-In/Early-Out cutting: remove pleasantry exits, purpose hand-holding, and narrator glue.",
180
+ });
181
+ }
182
+
183
+ // 0c. 校验连续多个自然段以第三人称代词起头(读着像翻译腔)
184
+ const maxPronounGate =
185
+ gates.maxPronounHeadStreak !== undefined ? gates.maxPronounHeadStreak : 2;
186
+ if (m.maxPronounHeadStreak > maxPronounGate) {
187
+ violations.push({
188
+ code: "PRONOUN_HEAD_STREAK",
189
+ actual: m.maxPronounHeadStreak,
190
+ maxAllowed: maxPronounGate,
191
+ spans: d.pronounStreakSpans,
192
+ remedy:
193
+ "Avoid starting 3+ consecutive paragraphs the same way; vary with a name, a concrete object or sound, but keep the actor clear.",
194
+ });
195
+ }
196
+
197
+ // 0c2. 主语连续性:省略主语后可能被读成别人的动作;连续多段用同一种方式起头(需要台账人物名单)
198
+ const { names: characterNames, protagonistNames } = collectCharacterNames(
199
+ options.ledger,
200
+ options.characterNames || []
201
+ );
202
+ const continuity = scanSubjectContinuity(d.paragraphs, lingConfig, {
203
+ names: characterNames,
204
+ protagonistNames,
205
+ });
206
+ if (continuity.ambiguityHits.length > 0) {
207
+ violations.push({
208
+ code: "SUBJECT_AMBIGUITY",
209
+ count: continuity.ambiguityHits.length,
210
+ hits: continuity.ambiguityHits,
211
+ remedy:
212
+ "The previous sentence's subject is another character and this action sentence has no subject; name the actor (or use a pronoun) so the action is not read as the other character's.",
213
+ });
214
+ }
215
+ if (continuity.openingStreaks.length > 0) {
216
+ violations.push({
217
+ code: "OPENING_PATTERN_STREAK",
218
+ count: continuity.openingStreaks.length,
219
+ spans: continuity.openingStreaks,
220
+ remedy:
221
+ "Three or more consecutive paragraphs open the same way (action-then-subject, subjectless action, or the protagonist's name); vary the openings.",
222
+ });
223
+ }
224
+
225
+ // 0d. 校验对话标点硬伤(说话人提示语居中误用冒号、句号误落引号外)
226
+ const rawDialogueHits = scanParagraphRuleSet(
227
+ d.paragraphs,
228
+ dialogueHygieneRules,
229
+ scanOpts
230
+ );
231
+ const dialogueEval = evaluateHitsWithDensity(
232
+ rawDialogueHits,
233
+ dialogueHygieneRules,
234
+ m.totalHan
235
+ );
236
+ const dialogueHits = dialogueEval.hits;
237
+ if (dialogueHits.length > 0) {
238
+ violations.push({
239
+ code: "DIALOGUE_PUNCTUATION_ERROR",
240
+ count: dialogueHits.length,
241
+ hits: dialogueHits,
242
+ forceSeverity: dialogueEval.hasBlocking ? "error" : undefined,
243
+ remedy:
244
+ "Fix dialogue attribution punctuation errors (mid-turn colon after comma-closed quote or period placed outside closing quote).",
245
+ });
246
+ }
247
+
248
+ // 1. 校验有效汉字字数区间(可选跳过用于短片段基准测试)
249
+ if (!options.skipLengthGate) {
250
+ if (m.totalHan < gates.minHanChars || m.totalHan > gates.maxHanChars) {
251
+ violations.push({
252
+ code: "WORD_COUNT_OUT_OF_RANGE",
253
+ actual: m.totalHan,
254
+ expected: [gates.minHanChars, gates.maxHanChars],
255
+ remedy: "Adjust scene pacing to stay within chapter target length.",
256
+ });
257
+ }
258
+ }
259
+
260
+ // 2. 校验自然段最大字数限制
261
+ const oversizedParas = d.paragraphs.filter(
262
+ (p) => p.hanLen > gates.maxParagraphHanChars
263
+ );
264
+ if (oversizedParas.length > 0) {
265
+ violations.push({
266
+ code: "PARAGRAPH_TOO_LONG",
267
+ count: oversizedParas.length,
268
+ lines: oversizedParas.map((p) => ({ line: p.line, hanLen: p.hanLen })),
269
+ remedy: "Split dense walls of text at natural action or gaze shifts.",
270
+ });
271
+ }
272
+
273
+ // 2b. 校验单句最大汉字数与逗号上限(抑制机械动作清单长链)
274
+ const maxSentHanGate = gates.maxSentenceHanChars || 90;
275
+ const maxSentCommasGate = gates.maxSentenceCommas || 7;
276
+ const overloadedSentences = (d.sentences || []).filter(
277
+ (s) => s.hanLen > maxSentHanGate || s.commaCount > maxSentCommasGate
278
+ );
279
+ if (overloadedSentences.length > 0) {
280
+ violations.push({
281
+ code: "OVERLOADED_ACTION_CHAIN_SENTENCE",
282
+ count: overloadedSentences.length,
283
+ maxAllowedHan: maxSentHanGate,
284
+ maxAllowedCommas: maxSentCommasGate,
285
+ hits: overloadedSentences,
286
+ remedy:
287
+ "Break 90+ char or 8+ comma mechanical action checklists into crisp sequential sentences with natural breathing pauses.",
288
+ });
289
+ }
290
+
291
+ // 2c. 校验单个自然段内的专有名词与复合词全称机械复读(引导零指代省略与简称)
292
+ const maxCompoundRep = gates.maxParagraphCompoundRepeat || 2;
293
+ const maxTwoCharRep = gates.maxParagraphTwoCharRepeat || 3;
294
+ const stuffingViolations = (d.paragraphStuffingScan || []).filter(
295
+ (rec) =>
296
+ rec.bookTitleRepeats.length > 0 ||
297
+ rec.compoundRepeats.some((r) => r.count > maxCompoundRep) ||
298
+ rec.twoCharRepeats.some((r) => r.count > maxTwoCharRep)
299
+ );
300
+ if (stuffingViolations.length > 0) {
301
+ violations.push({
302
+ code: "PARAGRAPH_TERM_STUFFING",
303
+ count: stuffingViolations.length,
304
+ hits: stuffingViolations,
305
+ remedy:
306
+ "Avoid repeating full proper nouns or 3+ char terms 3+ times inside one paragraph; use Chinese zero-anaphora omission or natural short forms.",
307
+ });
308
+ }
309
+
310
+ // 2e. 校验全章级口癖短语与器物复合词听觉疲劳复读(豁免台账角色人名与别名)
311
+ if (gates.maxChapterFourGramRepeat || gates.maxChapterThreeGramRepeat) {
312
+ const exemptNames = new Set(characterNames);
313
+ const isNameAdjacent = (term) => {
314
+ for (const name of exemptNames) {
315
+ if (name && (term.includes(name) || name.includes(term))) {
316
+ return true;
317
+ }
318
+ }
319
+ return false;
320
+ };
321
+ const maxChap4 = gates.maxChapterFourGramRepeat || 99;
322
+ const maxChap3 = gates.maxChapterThreeGramRepeat || 99;
323
+ const fatiguedFour = (d.chapterFourGramFreq || []).filter(
324
+ (item) => item.count > maxChap4 && !isNameAdjacent(item.term)
325
+ );
326
+ const fatiguedThree = (d.chapterThreeGramFreq || []).filter(
327
+ (item) => item.count > maxChap3 && !isNameAdjacent(item.term)
328
+ );
329
+ if (fatiguedFour.length > 0 || fatiguedThree.length > 0) {
330
+ violations.push({
331
+ code: "CHAPTER_TERM_FATIGUE",
332
+ fourGramHits: fatiguedFour,
333
+ threeGramHits: fatiguedThree,
334
+ remedy:
335
+ "Avoid repeating 4-char catchphrases (>3x) or 3-char prop/venue full names (>8x) across the chapter; switch to natural short forms after initial anchoring.",
336
+ });
337
+ }
338
+ }
339
+
340
+ // 2f. 校验场景开场首句悬空台词(防止首句对白孤立成段缺少说话人锚点)
341
+ if (
342
+ gates.maxFloatingDialogueCount !== undefined &&
343
+ m.floatingDialogueCount > gates.maxFloatingDialogueCount
344
+ ) {
345
+ violations.push({
346
+ code: "FLOATING_OPENING_DIALOGUE",
347
+ count: m.floatingDialogueCount,
348
+ hits: d.floatingDialogueHits,
349
+ remedy:
350
+ "Anchor the first line of a dialogue exchange to a speaker action/beat instead of leaving an isolated quote paragraph.",
351
+ });
352
+ }
353
+
354
+ // 2d. 校验连续无对白纯叙述/设定堆砌干涸跨度(融合网文动作-反应留存律与防滑窗静态独白检测)
355
+ const maxDryGate = gates.maxDialogueDrySpellHan || 1200;
356
+ if (m.totalHan >= 1500 && m.maxDialogueDrySpellHan > maxDryGate) {
357
+ const offendingSpans = (d.dialogueDrySpells || []).filter(
358
+ (sp) => sp.hanSpan > maxDryGate
359
+ );
360
+ violations.push({
361
+ code: "EXPOSITION_DIALOGUE_DROUGHT",
362
+ actualMaxSpan: m.maxDialogueDrySpellHan,
363
+ maxAllowedSpan: maxDryGate,
364
+ spans: offendingSpans,
365
+ remedy:
366
+ "Break long static monologue or world-building exposition blocks (>950 chars without spoken interaction) using live action-reaction dialogue beats.",
367
+ });
368
+ }
369
+
370
+ // 3. 校验双向词汇熵走廊(MATTR-50、一次性词占比与话题锚定上下界:左防AI塑料换词,右防笔录硬复读)
371
+ if (m.mattr50 > gates.maxMattr50) {
372
+ violations.push({
373
+ code: "HIGH_LEXICAL_ENTROPY_MATTR",
374
+ actual: m.mattr50,
375
+ maxAllowed: gates.maxMattr50,
376
+ remedy:
377
+ "Replace ornate two-char literary verbs/adjectives with plain vernacular verbs instead of rotating fancy synonyms.",
378
+ });
379
+ }
380
+ if (gates.maxHapaxRatio && m.hapaxRatio > gates.maxHapaxRatio) {
381
+ violations.push({
382
+ code: "EXCESSIVE_HAPAX_SYNONYM_CHURN",
383
+ actual: m.hapaxRatio,
384
+ maxAllowed: gates.maxHapaxRatio,
385
+ remedy:
386
+ "Too many one-off literary compounds; strip decorative modifiers and stick to plain conversational diction.",
387
+ });
388
+ }
389
+ if (m.sentenceCount >= 8 && m.topicAnchorRatio < gates.minTopicAnchorRatio) {
390
+ violations.push({
391
+ code: "LOW_TOPIC_ANCHOR_RECURRENCE",
392
+ actual: m.topicAnchorRatio,
393
+ minRequired: gates.minTopicAnchorRatio,
394
+ remedy:
395
+ "Link adjacent sentences via natural vernacular connectors rather than jumping across unrelated literary imagery.",
396
+ });
397
+ }
398
+ if (
399
+ gates.maxTopicAnchorRatio &&
400
+ m.sentenceCount >= 8 &&
401
+ m.topicAnchorRatio > gates.maxTopicAnchorRatio
402
+ ) {
403
+ violations.push({
404
+ code: "EXCESSIVE_TOPIC_ANCHOR_STUFFING",
405
+ actual: m.topicAnchorRatio,
406
+ maxAllowed: gates.maxTopicAnchorRatio,
407
+ remedy:
408
+ "Stop repeating full nouns in every sentence like a police transcript; use Chinese subject/object omission and pronoun 'ta'.",
409
+ });
410
+ }
411
+
412
+ // 4. 校验双峰呼吸突发度(句长变异系数 CV、竹节长句占比与冷峻极短句占比)
413
+ if (m.sentenceCount >= 8 && m.sentLenCV < gates.minSentLenCV) {
414
+ violations.push({
415
+ code: "FLAT_BURSTINESS_CV",
416
+ actual: m.sentLenCV,
417
+ minRequired: gates.minSentLenCV,
418
+ remedy:
419
+ "Interleave crisp <=10-char cuts with 4-7 comma bamboo-joint serial sentences to break uniform sentence length.",
420
+ });
421
+ }
422
+ if (m.sentenceCount >= 8 && m.flowingSentRatio < gates.minFlowingSentRatio) {
423
+ violations.push({
424
+ code: "INSUFFICIENT_FLOWING_PARATAXIS",
425
+ actual: m.flowingSentRatio,
426
+ minRequired: gates.minFlowingSentRatio,
427
+ remedy:
428
+ "Merge choppy 2-clause sentences into subject-omitted serial verb chains with 4+ commas.",
429
+ });
430
+ }
431
+ if (
432
+ m.sentenceCount >= 8 &&
433
+ m.ultraShortSentRatio < gates.minUltraShortSentRatio
434
+ ) {
435
+ violations.push({
436
+ code: "INSUFFICIENT_ULTRA_SHORT_CUTS",
437
+ actual: m.ultraShortSentRatio,
438
+ minRequired: gates.minUltraShortSentRatio,
439
+ remedy:
440
+ "Insert brisk <=10-char kinetic beats or stark observations at turning points.",
441
+ });
442
+ }
443
+ if (d.monotonousWindows.length > 0) {
444
+ violations.push({
445
+ code: "MONOTONOUS_CADENCE_WINDOW",
446
+ windows: d.monotonousWindows,
447
+ remedy:
448
+ "Rewrite monotonous 6-sentence spans where sentence lengths cluster tightly.",
449
+ });
450
+ }
451
+
452
+ // 5. 校验欧化左分支定语密度与嵌套“的”链
453
+ if (m.dePer100Han > gates.maxDePer100Han) {
454
+ violations.push({
455
+ code: "EXCESSIVE_DE_MODIFIER_DENSITY",
456
+ actual: m.dePer100Han,
457
+ maxAllowed: gates.maxDePer100Han,
458
+ remedy:
459
+ "Unpack pre-nominal 'X-de-Noun' modifiers into post-verbal clauses or plain bare nouns.",
460
+ });
461
+ }
462
+ if (m.longModPerClause > gates.maxLongModPerClause) {
463
+ violations.push({
464
+ code: "HEAVY_LEFT_BRANCHING_MODIFIERS",
465
+ actual: m.longModPerClause,
466
+ maxAllowed: gates.maxLongModPerClause,
467
+ sampleHits: d.longModifierHits.slice(0, 8),
468
+ remedy:
469
+ "Break >=7-char pre-de modifier chains into sequential bamboo-joint clauses.",
470
+ });
471
+ }
472
+ if (m.nestedDePer1kHan > gates.maxNestedDePer1kHan) {
473
+ violations.push({
474
+ code: "NESTED_DE_CHAINS",
475
+ actual: m.nestedDePer1kHan,
476
+ maxAllowed: gates.maxNestedDePer1kHan,
477
+ hits: d.nestedDeHits.slice(0, 8),
478
+ remedy: "Eliminate nested 'A-de-B-de-C' structures.",
479
+ });
480
+ }
481
+
482
+ // 6. 校验标点代劳语法、修辞反问、对称骨架与禁用雕花词
483
+ if (m.emDashPer1kHan > gates.maxEmDashPer1kHan) {
484
+ violations.push({
485
+ code: "EM_DASH_OVERUSE",
486
+ actual: m.emDashPer1kHan,
487
+ maxAllowed: gates.maxEmDashPer1kHan,
488
+ hits: d.emDashHits,
489
+ remedy: "Replace narrative em-dashes with commas or direct clauses.",
490
+ });
491
+ }
492
+ if (m.rhetoricalQuestionCount > gates.maxRhetoricalQuestionCount) {
493
+ violations.push({
494
+ code: "NARRATIVE_RHETORICAL_QUESTIONS",
495
+ actual: m.rhetoricalQuestionCount,
496
+ maxAllowed: gates.maxRhetoricalQuestionCount,
497
+ hits: d.rhetoricalQuestionHits,
498
+ remedy:
499
+ "Convert paragraph-ending rhetorical questions into plain causal statements.",
500
+ });
501
+ }
502
+ // 6b. 评估对称骨架与AI雕花套话密度/必改分级(与反序对比共享 not_is 家族计数)
503
+ const rawRhetHits = scanParagraphRuleSet(d.paragraphs, rhetoricalRules, scanOpts);
504
+ const crossCfg = lingConfig.compiledRegex.crossParagraphParallel;
505
+ const crossHits =
506
+ crossCfg && !disabled.has(crossCfg.id)
507
+ ? scanCrossParagraphParallel(d.paragraphs, crossCfg, scanOpts)
508
+ : [];
509
+
510
+ const symFamCounts = countRuleFamily(d.symmetricHits, symmetricRules);
511
+ const rhetFamCounts = countRuleFamily(rawRhetHits, rhetoricalRules);
512
+ const symEval = evaluateHitsWithDensity(
513
+ d.symmetricHits,
514
+ symmetricRules,
515
+ m.totalHan,
516
+ rhetFamCounts
517
+ );
518
+ const rhetEval = evaluateHitsWithDensity(
519
+ rawRhetHits,
520
+ rhetoricalRules,
521
+ m.totalHan,
522
+ symFamCounts
523
+ );
524
+ const combinedRhetHits = [...rhetEval.hits, ...crossHits];
525
+
526
+ const clicheEval = evaluateHitsWithDensity(d.clicheHits, clicheRules, m.totalHan);
527
+ const activeClicheHits = clicheEval.hits;
528
+
529
+ if (symEval.hits.length > gates.maxSymmetricSkeletonCount || symEval.hasBlocking) {
530
+ violations.push({
531
+ code: "MECHANICAL_SYMMETRIC_SKELETON",
532
+ actual: symEval.hits.length,
533
+ maxAllowed: gates.maxSymmetricSkeletonCount,
534
+ hits: symEval.hits,
535
+ forceSeverity: symEval.hasBlocking ? "error" : undefined,
536
+ remedy:
537
+ "Dismantle 'not A, but B' / 'seemingly X, actually Y' contrastive frames.",
538
+ });
539
+ }
540
+ if (combinedRhetHits.length > 0) {
541
+ violations.push({
542
+ code: "RHETORICAL_AI_PATTERN",
543
+ count: combinedRhetHits.length,
544
+ hits: combinedRhetHits,
545
+ forceSeverity: rhetEval.hasBlocking ? "error" : undefined,
546
+ remedy:
547
+ "Remove volume-contrast, negation-parade, reverse-not-is, or chapter-trailer summary patterns in narration.",
548
+ });
549
+ }
550
+ if (activeClicheHits.length > 0) {
551
+ violations.push({
552
+ code: "FORBIDDEN_AI_CLICHE",
553
+ count: activeClicheHits.length,
554
+ hits: activeClicheHits,
555
+ forceSeverity: clicheEval.hasBlocking ? "error" : undefined,
556
+ remedy:
557
+ "Remove AI micro-acting cliches, purple-prose verbs, and modern slang.",
558
+ });
559
+ }
560
+
561
+ // 6c. 密度型文风探针(微动作、套式反应、动作清单、引号强调、电报体反向守卫等)
562
+ const densityTics = runDensityTics(
563
+ d.paragraphs,
564
+ lingConfig,
565
+ whitelistLiterals,
566
+ disabled
567
+ );
568
+ if (densityTics.length > 0) {
569
+ violations.push({
570
+ code: "PROSE_DENSITY_TIC",
571
+ count: densityTics.length,
572
+ hits: densityTics,
573
+ remedy:
574
+ "Review density-flagged prose habits (micro-actions, stock reactions, quote emphasis, or telegraphic over-compression) in context.",
575
+ });
576
+ }
577
+
578
+ // 6d. 模型退化与工程词泄漏检测(复读、截断、AI自指、Tier1/Tier2 工程词)
579
+ const { degenerationHits, metaLeakHits } = runDegenerationChecks(
580
+ rawContent,
581
+ lingConfig,
582
+ whitelistLiterals,
583
+ disabled
584
+ );
585
+ if (degenerationHits.length > 0) {
586
+ violations.push({
587
+ code: "DEGENERATION_DETECTED",
588
+ count: degenerationHits.length,
589
+ hits: degenerationHits,
590
+ forceSeverity: "error",
591
+ remedy:
592
+ "Fix hard model degeneration artifacts (verbatim loops, truncated ending, garbled chars, or AI refusal placeholders).",
593
+ });
594
+ }
595
+ if (metaLeakHits.length > 0) {
596
+ const hasTier1 = metaLeakHits.some((h) => h.level === "blocking");
597
+ violations.push({
598
+ code: "ENGINEERING_META_LEAK",
599
+ count: metaLeakHits.length,
600
+ hits: metaLeakHits,
601
+ forceSeverity: hasTier1 ? "error" : undefined,
602
+ remedy:
603
+ "Purge outline/chapter engineering terms from novel prose; replace with in-world sensory time/event anchors.",
604
+ });
605
+ }
606
+
607
+ if (m.formattingArtifactCount > 0) {
608
+ violations.push({
609
+ code: "FORMATTING_OR_LEDGER_ARTIFACTS",
610
+ count: m.formattingArtifactCount,
611
+ bracketNotes: d.bracketNoteHits,
612
+ asterisks: d.asteriskHits,
613
+ remedy: "Strip markdown asterisks and inline ledger parentheticals.",
614
+ });
615
+ }
616
+
617
+ // 7. 校验段落句数聚拢度与“一句一段”机器排版连击
618
+ if (
619
+ m.paragraphCount >= 6 &&
620
+ (m.sentsPerParaMean < gates.minSentsPerPara ||
621
+ m.sentsPerParaMean > gates.maxSentsPerPara)
622
+ ) {
623
+ violations.push({
624
+ code: "UNNATURAL_PARAGRAPH_DENSITY",
625
+ actual: m.sentsPerParaMean,
626
+ expected: [gates.minSentsPerPara, gates.maxSentsPerPara],
627
+ remedy:
628
+ "Group related narrative actions into 2-3 sentence paragraphs while reserving 1-sentence paragraphs for sharp beats.",
629
+ });
630
+ }
631
+ if (m.maxSingleSentParaStreak > gates.maxSingleSentParaStreak) {
632
+ violations.push({
633
+ code: "SINGLE_SENTENCE_PARAGRAPH_STREAK",
634
+ actual: m.maxSingleSentParaStreak,
635
+ maxAllowed: gates.maxSingleSentParaStreak,
636
+ remedy:
637
+ "Break robotic one-sentence-per-line formatting by merging continuous action beats.",
638
+ });
639
+ }
640
+
641
+ // 8. 若提供全书台账,联合执行硬边界、防剧透与必达锚点核验
642
+ let boundaryReport = null;
643
+ if (options.ledger && options.chapterNumber) {
644
+ boundaryReport = verifyChapterBoundaries(
645
+ rawContent,
646
+ options.ledger,
647
+ options.chapterNumber,
648
+ options.previousChapterText || "",
649
+ lingConfig
650
+ );
651
+ if (boundaryReport.boundaryEchoRatio > gates.maxBoundaryEchoRatio) {
652
+ violations.push({
653
+ code: "PREVIOUS_ENDING_ECHO",
654
+ actual: boundaryReport.boundaryEchoRatio,
655
+ maxAllowed: gates.maxBoundaryEchoRatio,
656
+ remedy:
657
+ "Advance directly from the prior chapter's final state without replaying its closing lines.",
658
+ });
659
+ }
660
+ if (!boundaryReport.pass) {
661
+ violations.push({
662
+ code: "LEDGER_BOUNDARY_VIOLATION",
663
+ details: boundaryReport,
664
+ remedy:
665
+ "Fix missing required anchors, remove future spoilers, or purge deprecated character names.",
666
+ });
667
+ }
668
+ if (boundaryReport.deceasedHits && boundaryReport.deceasedHits.length > 0) {
669
+ violations.push({
670
+ code: "DECEASED_CHARACTER_APPEARANCE",
671
+ count: boundaryReport.deceasedHits.length,
672
+ hits: boundaryReport.deceasedHits,
673
+ remedy:
674
+ "Character is marked deceased/exited in earlier chapters; verify this is an explicit flashback or fix continuity.",
675
+ });
676
+ }
677
+ if (boundaryReport.unresolvedProps && boundaryReport.unresolvedProps.length > 0) {
678
+ violations.push({
679
+ code: "UNRESOLVED_TACTICAL_PROP",
680
+ count: boundaryReport.unresolvedProps.length,
681
+ hits: boundaryReport.unresolvedProps,
682
+ remedy:
683
+ "Resolve or mention the planted short-term tactical prop by its deadline chapter, or mark it paid_off/abandoned in ledger.",
684
+ });
685
+ }
686
+ if (boundaryReport.worldRuleHits && boundaryReport.worldRuleHits.length > 0) {
687
+ violations.push({
688
+ code: "WORLD_RULE_VIOLATION",
689
+ count: boundaryReport.worldRuleHits.length,
690
+ hits: boundaryReport.worldRuleHits,
691
+ remedy:
692
+ "Prose violates an immutableWorldRules forbiddenPattern in ledger.json; align with world-building constraints.",
693
+ });
694
+ }
695
+ } else if (
696
+ options.previousChapterText &&
697
+ options.previousChapterText.trim().length > 0
698
+ ) {
699
+ const echoRatio = computeBoundaryEchoRatio(
700
+ rawContent,
701
+ options.previousChapterText,
702
+ lingConfig
703
+ );
704
+ if (echoRatio > gates.maxBoundaryEchoRatio) {
705
+ violations.push({
706
+ code: "PREVIOUS_ENDING_ECHO",
707
+ actual: echoRatio,
708
+ maxAllowed: gates.maxBoundaryEchoRatio,
709
+ remedy:
710
+ "Advance directly from the prior chapter's final state without replaying its closing lines.",
711
+ });
712
+ }
713
+ }
714
+
715
+ // 9. 若提供本章细纲文本,执行防抄纲重叠检测
716
+ let outlineCopyReport = null;
717
+ if (options.outlineText) {
718
+ outlineCopyReport = checkOutlineCopy(rawContent, options.outlineText, {
719
+ lingConfig,
720
+ minRun: options.outlineMinRun,
721
+ exemptPhrases: options.outlineExemptPhrases,
722
+ });
723
+ if (!outlineCopyReport.pass) {
724
+ violations.push({
725
+ code: "OUTLINE_COPY_DETECTED",
726
+ overlapCount: outlineCopyReport.overlapCount,
727
+ minRun: outlineCopyReport.minRun,
728
+ hits: outlineCopyReport.hits.slice(0, 12),
729
+ remedy:
730
+ "Render beats with sensory actions and dialogue instead of copying outline prose verbatim.",
731
+ });
732
+ }
733
+ }
734
+
735
+ // 10. 校验相邻引号的“短短 X 字 / 这 X 个字”字面字数宣称与实字数是否穿帮
736
+ const charCountHits = disabled.has("char_count_claim_mismatch")
737
+ ? []
738
+ : checkCharCountClaims(rawContent, lingConfig, whitelistLiterals);
739
+ if (charCountHits.length > 0) {
740
+ violations.push({
741
+ code: "CHAR_COUNT_CLAIM_MISMATCH",
742
+ count: charCountHits.length,
743
+ hits: charCountHits,
744
+ remedy:
745
+ "Align stated character count with the actual characters inside the adjacent quotation.",
746
+ });
747
+ }
748
+
749
+ // 11. 校验同章历法日期跨度与“半个月”宣称是否自相矛盾
750
+ const calendarHits = disabled.has("calendar_span_contradiction")
751
+ ? []
752
+ : checkCalendarSpanContradictions(rawContent, lingConfig);
753
+ if (calendarHits.length > 0) {
754
+ violations.push({
755
+ code: "CALENDAR_SPAN_CONTRADICTION",
756
+ count: calendarHits.length,
757
+ hits: calendarHits,
758
+ remedy:
759
+ "Reconcile stated lunar month/day span with the half-month duration claim in the same chapter.",
760
+ });
761
+ }
762
+
763
+ // 12. 黄金三章首屏留存专项门禁(--golden-three 开启时检查首屏前 380 字是否有对白或突发冲突)
764
+ let goldenOpeningReport = null;
765
+ if (options.goldenThree && !disabled.has("golden_opening_slow_start")) {
766
+ goldenOpeningReport = checkGoldenOpeningPacing(rawContent, lingConfig);
767
+ if (goldenOpeningReport && goldenOpeningReport.slowStart) {
768
+ violations.push({
769
+ code: "GOLDEN_OPENING_SLOW_START",
770
+ details: goldenOpeningReport,
771
+ remedy:
772
+ "Front-load dialogue, unexpected action, or anomalous evidence within the first 380 Han characters for Golden-Three retention.",
773
+ });
774
+ }
775
+ }
776
+
777
+ // 13. 离线 280 字滑窗 AIGC 结构句式熵与虚词双侧护栏扫描
778
+ const aigcGuardActive = Boolean(options.aigcGuard || gates.aigcGuard);
779
+ const aigcThreshold =
780
+ options.aigcThreshold !== undefined
781
+ ? Number(options.aigcThreshold)
782
+ : gates.aigcWindowThreshold !== undefined
783
+ ? Number(gates.aigcWindowThreshold)
784
+ : 0.5;
785
+ const aigcReport = scanChapterAigcWindows(rawContent, {
786
+ threshold: aigcThreshold,
787
+ exemptTerms: [...characterNames, ...whitelistLiterals],
788
+ });
789
+ m.cadenceEntropy = aigcReport.chapterCadence.cadenceEntropy;
790
+ m.sandwichParaRatio = aigcReport.chapterCadence.sandwichRatio;
791
+ m.demonsPer100Han = aigcReport.chapterCadence.demonsPer100Han;
792
+ m.maxWindowAigcRisk = aigcReport.maxWindowRisk;
793
+
794
+ if (
795
+ !disabled.has("cadence_template_monotony") &&
796
+ aigcReport.monotonySpans.length > 0
797
+ ) {
798
+ violations.push({
799
+ code: "CADENCE_TEMPLATE_MONOTONY",
800
+ count: aigcReport.monotonySpans.length,
801
+ spans: aigcReport.monotonySpans,
802
+ forceSeverity: aigcGuardActive ? "warning" : undefined,
803
+ remedy:
804
+ "Break 4+ consecutive mid-attribution sandwich quotes (S) or 8+ action-colon (A) paragraphs by mixing pure narration (N) and bare-quote (Q) turns.",
805
+ });
806
+ }
807
+ if (
808
+ !disabled.has("telegraphic_modifier_stuffing") &&
809
+ aigcReport.telegraphicSpans.length > 0
810
+ ) {
811
+ violations.push({
812
+ code: "TELEGRAPHIC_MODIFIER_STUFFING",
813
+ count: aigcReport.telegraphicSpans.length,
814
+ windows: aigcReport.telegraphicSpans,
815
+ forceSeverity: aigcGuardActive ? "warning" : undefined,
816
+ remedy:
817
+ "Over-dehydrated prose (<0.9/100 'de') with demonstrative 'zhe/na' spike and >=5-char modifier bricks triggers AIGC rebound; restore natural spoken particles.",
818
+ });
819
+ }
820
+ if (
821
+ aigcGuardActive &&
822
+ !disabled.has("aigc_window_risk") &&
823
+ !aigcReport.pass
824
+ ) {
825
+ violations.push({
826
+ code: "AIGC_WINDOW_RISK",
827
+ count: aigcReport.flaggedWindows.length,
828
+ maxRisk: aigcReport.maxWindowRisk,
829
+ threshold: aigcReport.threshold,
830
+ windows: aigcReport.flaggedWindows,
831
+ forceSeverity: "warning",
832
+ remedy:
833
+ "280-char window exceeds AIGC structural risk threshold; rebalance N/A/Q/S paragraph cadence, keep 'de' in 1.45-2.15/100, and cut 'zhe/na' below 1.15/100.",
834
+ });
835
+ }
836
+
837
+ // 汇总需要局部动刀的精确行号手术单(供 Stage 4 qu-ai-wei 靶向手术刀消费)
838
+ const surgeryLineMap = new Map();
839
+ const registerLineIssue = (line, tag, detail, meta = null) => {
840
+ if (!line) return;
841
+ const existing = surgeryLineMap.get(line) || [];
842
+ const entry = { tag, detail };
843
+ if (meta?.layer) entry.layer = meta.layer;
844
+ if (meta?.level) entry.level = meta.level;
845
+ if (meta?.review) entry.review = meta.review;
846
+ existing.push(entry);
847
+ surgeryLineMap.set(line, existing);
848
+ };
849
+
850
+ registerHits.forEach((h) => registerLineIssue(h.line, h.id, h.matched, h));
851
+ fillerHits.forEach((h) => registerLineIssue(h.line, h.id, h.matched, h));
852
+ dialogueHits.forEach((h) => registerLineIssue(h.line, h.id, h.matched, h));
853
+ if (m.maxPronounHeadStreak > maxPronounGate) {
854
+ (d.pronounStreakSpans || []).forEach((sp) =>
855
+ registerLineIssue(
856
+ sp.startLine,
857
+ "pronoun_head_streak",
858
+ `${sp.streak} consecutive pronoun-initial paragraphs (lines ${sp.startLine}-${sp.endLine})`
859
+ )
860
+ );
861
+ }
862
+ continuity.ambiguityHits.forEach((h) =>
863
+ registerLineIssue(
864
+ h.line,
865
+ "subject_ambiguity",
866
+ `previous actor ${h.previousActor}: ${h.current}`
867
+ )
868
+ );
869
+ continuity.openingStreaks.forEach((sp) =>
870
+ registerLineIssue(
871
+ sp.startLine,
872
+ "opening_pattern_streak",
873
+ `${sp.streak} consecutive ${sp.kind} openings (lines ${sp.startLine}-${sp.endLine})`
874
+ )
875
+ );
876
+ activeClicheHits.forEach((h) => registerLineIssue(h.line, h.id, h.matched, h));
877
+ d.emDashHits.forEach((h) => registerLineIssue(h.line, "em_dash", h.preview));
878
+ d.rhetoricalQuestionHits.forEach((h) =>
879
+ registerLineIssue(h.line, "rhetorical_question", h.preview)
880
+ );
881
+ symEval.hits.forEach((h) => registerLineIssue(h.line, h.id, h.matched, h));
882
+ combinedRhetHits.forEach((h) =>
883
+ registerLineIssue(h.line, h.id, h.matched, h)
884
+ );
885
+ densityTics.forEach((t) =>
886
+ registerLineIssue(
887
+ t.line,
888
+ t.id,
889
+ `${t.hits}x${t.perKilo ? ` (${t.perKilo}/1k)` : ""}: ${(t.samples || []).slice(0, 4).join(" / ")}`,
890
+ t
891
+ )
892
+ );
893
+ degenerationHits.forEach((h) =>
894
+ registerLineIssue(h.line, h.id, h.matched, h)
895
+ );
896
+ metaLeakHits.forEach((h) => registerLineIssue(h.line, h.id, h.matched, h));
897
+ d.nestedDeHits.forEach((h) =>
898
+ registerLineIssue(h.line, "nested_de", h.matched)
899
+ );
900
+ oversizedParas.forEach((p) =>
901
+ registerLineIssue(p.line, "oversized_paragraph", `${p.hanLen} chars`)
902
+ );
903
+ if (
904
+ gates.maxFloatingDialogueCount !== undefined &&
905
+ m.floatingDialogueCount > gates.maxFloatingDialogueCount
906
+ ) {
907
+ (d.floatingDialogueHits || []).forEach((h) =>
908
+ registerLineIssue(h.line, "floating_opening_dialogue", h.preview)
909
+ );
910
+ }
911
+ overloadedSentences.forEach((s) =>
912
+ registerLineIssue(
913
+ s.line,
914
+ "overloaded_sentence",
915
+ `${s.hanLen} chars / ${s.commaCount} commas: ${s.preview}`
916
+ )
917
+ );
918
+ stuffingViolations.forEach((rec) => {
919
+ const summary = [
920
+ ...rec.bookTitleRepeats.map((r) => `${r.term}x${r.count}`),
921
+ ...rec.compoundRepeats.map((r) => `${r.term}x${r.count}`),
922
+ ...rec.twoCharRepeats.map((r) => `${r.term}x${r.count}`),
923
+ ].join(", ");
924
+ registerLineIssue(rec.line, "paragraph_term_stuffing", summary);
925
+ });
926
+ if (m.totalHan >= 1500 && m.maxDialogueDrySpellHan > maxDryGate) {
927
+ (d.dialogueDrySpells || [])
928
+ .filter((sp) => sp.hanSpan > maxDryGate)
929
+ .forEach((sp) =>
930
+ registerLineIssue(
931
+ sp.startLine,
932
+ "exposition_dialogue_drought",
933
+ `${sp.hanSpan} chars without spoken dialogue (lines ${sp.startLine}-${sp.endLine})`
934
+ )
935
+ );
936
+ }
937
+ if (outlineCopyReport && !outlineCopyReport.pass) {
938
+ outlineCopyReport.hits.forEach((h) =>
939
+ registerLineIssue(
940
+ h.line,
941
+ "outline_copy",
942
+ `${h.length} chars verbatim from outline line ${h.outlineLine}: ${h.matched.slice(0, 24)}`,
943
+ { layer: "universal", level: "advisory", review: "mechanical" }
944
+ )
945
+ );
946
+ }
947
+ (d.bracketNoteHits || []).forEach((h) =>
948
+ registerLineIssue(h.line, "ledger_bracket_note", h.matched, {
949
+ layer: "universal",
950
+ level: "blocking",
951
+ review: "mechanical",
952
+ })
953
+ );
954
+ (d.asteriskHits || []).forEach((h) =>
955
+ registerLineIssue(h.line, "markdown_asterisk", h.preview || "*", {
956
+ layer: "universal",
957
+ level: "blocking",
958
+ review: "mechanical",
959
+ })
960
+ );
961
+ charCountHits.forEach((h) =>
962
+ registerLineIssue(
963
+ h.line,
964
+ "char_count_mismatch",
965
+ `${h.claimed} vs actual ${h.actual}: ${h.matched}`,
966
+ { layer: "universal", level: "blocking", review: "mechanical" }
967
+ )
968
+ );
969
+ (boundaryReport?.deceasedHits || []).forEach((h) =>
970
+ registerLineIssue(
971
+ h.line,
972
+ "deceased_character_appearance",
973
+ `${h.character} (${h.status} after ch${h.afterChapter ?? "?"}): ${h.matched}`,
974
+ { layer: "project", level: "advisory", review: "semantic" }
975
+ )
976
+ );
977
+ (boundaryReport?.unresolvedProps || []).forEach((p) =>
978
+ registerLineIssue(
979
+ 1,
980
+ "unresolved_tactical_prop",
981
+ `${p.anchorTerm} (planted ch${p.plantedChapter ?? "?"}, mustResolveBy ch${p.mustResolveByChapter})`,
982
+ { layer: "project", level: "advisory", review: "semantic" }
983
+ )
984
+ );
985
+ (boundaryReport?.worldRuleHits || []).forEach((h) =>
986
+ registerLineIssue(
987
+ h.line,
988
+ "world_rule_violation",
989
+ `${h.id}: ${h.matched} (${h.rule})`,
990
+ { layer: "project", level: "advisory", review: "semantic" }
991
+ )
992
+ );
993
+ calendarHits.forEach((h) =>
994
+ registerLineIssue(
995
+ h.line,
996
+ "calendar_span_contradiction",
997
+ `${h.matched} (~${h.actualSpanDays}d vs ~${h.claimedDays}d)`,
998
+ { layer: "universal", level: "advisory", review: "semantic" }
999
+ )
1000
+ );
1001
+ if (goldenOpeningReport && goldenOpeningReport.slowStart) {
1002
+ registerLineIssue(
1003
+ goldenOpeningReport.line || 1,
1004
+ "golden_opening_slow_start",
1005
+ `first ${goldenOpeningReport.windowHan} Han lacks dialogue (first dialogue at ${goldenOpeningReport.firstDialogueAtHan} Han)`,
1006
+ { layer: "universal", level: "advisory", review: "semantic" }
1007
+ );
1008
+ }
1009
+ if (aigcGuardActive) {
1010
+ aigcReport.monotonySpans.forEach((sp) =>
1011
+ registerLineIssue(
1012
+ sp.startLine,
1013
+ "cadence_template_monotony",
1014
+ `${sp.streak}x ${sp.kind} (lines ${sp.startLine}-${sp.endLine})`,
1015
+ { layer: "universal", level: "advisory", review: "semantic" }
1016
+ )
1017
+ );
1018
+ aigcReport.flaggedWindows.forEach((fw) =>
1019
+ registerLineIssue(
1020
+ fw.startLine,
1021
+ "aigc_window_risk",
1022
+ `risk=${fw.estimatedRisk} (L${fw.startLine}-L${fw.endLine}, seq=${fw.sequence}, de=${fw.dePer100}, dem=${fw.demonsPer100}): ${(fw.reasons || []).join(",") || "composite"}`,
1023
+ { layer: "universal", level: "advisory", review: "semantic" }
1024
+ )
1025
+ );
1026
+ }
1027
+
1028
+ const surgeryTargets = Array.from(surgeryLineMap.entries())
1029
+ .sort((a, b) => a[0] - b[0])
1030
+ .map(([line, issues]) => ({ line, issues }));
1031
+
1032
+ // 给每条违规标注分级;默认只有 error(blocking)判失败,strict 模式下任何违规都判失败
1033
+ for (const v of violations) {
1034
+ v.severity =
1035
+ v.forceSeverity || severity.byCode.get(v.code) || severity.defaultLevel;
1036
+ v.level =
1037
+ v.severity === "error"
1038
+ ? "blocking"
1039
+ : v.severity === "warning"
1040
+ ? "advisory"
1041
+ : "info";
1042
+ delete v.forceSeverity;
1043
+ }
1044
+ const countBy = (level) => violations.filter((v) => v.severity === level).length;
1045
+ const summary = {
1046
+ error: countBy("error"),
1047
+ warning: countBy("warning"),
1048
+ info: countBy("info"),
1049
+ };
1050
+ const strict = Boolean(options.strict);
1051
+ const pass = strict ? violations.length === 0 : summary.error === 0;
1052
+
1053
+ // 若提供人类参考区间,标出落在区间外的统计指标(只作对照,不判失败)
1054
+ const referenceComparison = options.reference
1055
+ ? compareWithReference(m, options.reference)
1056
+ : null;
1057
+
1058
+ return {
1059
+ pass,
1060
+ mode: strict ? "strict" : "default",
1061
+ scriptVariant,
1062
+ genre: genrePack ? genrePack.id : null,
1063
+ preset: preset.id,
1064
+ summary,
1065
+ metrics: m,
1066
+ referenceComparison,
1067
+ boundaryReport,
1068
+ outlineCopyReport,
1069
+ aigcReport,
1070
+ violationCount: violations.length,
1071
+ violations,
1072
+ surgeryTargets,
1073
+ };
1074
+ }