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,387 @@
1
+ // 零文件系统依赖的 280 字滑窗 AIGC 结构熵与词汇双侧护栏核心模块(供 Node CLI、MCP 与浏览器共用)
2
+
3
+ const RE_HAN_GLOBAL = /\p{Script=Han}/gu;
4
+ const RE_HAN_SINGLE = /\p{Script=Han}/u;
5
+ const RE_SENT_SPLIT = /[\u3002\uff01\uff1f!?]+/u;
6
+
7
+ // 引号与标点 Unicode 常量(避免代码字面量出现中文字符)
8
+ const OPEN_QUOTES = new Set(["\u201c", "\u300c", "\u300e"]);
9
+ const CLOSE_QUOTES = new Set(["\u201d", "\u300d", "\u300f"]);
10
+ const RE_QUOTE_SPAN = /\u201c[^\u201d\r\n]*\u201d|\u300c[^\u300d\r\n]*\u300d|\u300e[^\u300f\r\n]*\u300f/gu;
11
+ const RE_TRUE_SANDWICH =
12
+ /(?:\u201c[^\u201d\r\n]+\u201d|\u300c[^\u300d\r\n]+\u300d)[^\u201c\u201d\u300c\u300d\uff1a:\r\n]{1,36}[\uff0c,]\s*(?:\u201c[^\u201d\r\n]+\u201d|\u300c[^\u300d\r\n]+\u300d)/u;
13
+ const RE_PERIOD_BEFORE_QUOTE =
14
+ /(?<![\u201d\u300d\u300f\u201c\u300c\u300e])[\u3002\uff01\uff1f!?][^\S\r\n]*[\u201c\u300c\u300e]/gu;
15
+
16
+ const CH_DE = "\u7684";
17
+ const CH_ZHE_DEM = "\u8fd9";
18
+ const CH_NA_DEM = "\u90a3";
19
+
20
+ // 常用语法虚词、副词、人称代词、趋向词与数量词集合(用于识别无虚词硬拼的连续实词砖块)
21
+ const FUNC_CHAR_SET = new Set(
22
+ Array.from(
23
+ "\u7684\u5730\u5f97\u4e86\u7740\u8fc7\u5728\u628a\u88ab\u7ed9\u8ddf\u548c\u4e0e\u53ca\u6216\u5f80\u4ece\u5230\u5411\u4e4b" +
24
+ "\u662f\u6709\u6ca1\u4e0d\u4e5f\u90fd\u5c31\u8fd8\u53c8\u624d\u521a\u6b63\u5148\u518d\u66f4\u6700\u5f88\u633a\u592a\u771f\u53ea\u5374\u4f46" +
25
+ "\u80fd\u4f1a\u8981\u8ba9\u53eb\u53bb\u6765\u4e0a\u4e0b\u91cc\u5916\u597d\u5feb\u6162\u65e9\u665a\u591a\u5c11\u534a\u5168\u5404\u6bcf\u67d0\u522b\u53e6\u540c\u81ea\u76f8\u4e92" +
26
+ "\u4f60\u6211\u4ed6\u5979\u5b83\u60a8\u54b1\u8fd9\u90a3\u54ea\u8c01\u4ec0\u600e\u5417\u5427\u554a\u5462\u5457\u5566\u561b" +
27
+ "\u4e00\u4e8c\u4e24\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341\u767e\u5343\u4e07" +
28
+ "\u4e2a\u53ea\u5f20\u5757\u4ef6\u53e5\u58f0\u773c\u6b21\u70b9\u4e9b\u8bf4\u770b\u95ee\u60f3\u8d70"
29
+ )
30
+ );
31
+
32
+ // 统计字符串中的有效汉字数量
33
+ function countHanChars(text) {
34
+ const m = String(text || "").match(RE_HAN_GLOBAL);
35
+ return m ? m.length : 0;
36
+ }
37
+
38
+ // 统计指定单字符在文本中的出现次数
39
+ function countChar(text, target) {
40
+ let n = 0;
41
+ const s = String(text || "");
42
+ for (let i = 0; i < s.length; i += 1) {
43
+ if (s[i] === target) n += 1;
44
+ }
45
+ return n;
46
+ }
47
+
48
+ // 识别单个正文自然段的结构句式类别:
49
+ // N = 纯叙述段;S = 居中提示语夹心对话段;Q = 首引号单轮段;A = 动作冒号引出对话段;M = 多轮冒号复合段
50
+ export function classifyParagraphCadence(paragraphText) {
51
+ const p = String(paragraphText || "").trim();
52
+ if (!p) return "N";
53
+ let openCount = 0;
54
+ for (const ch of p) {
55
+ if (OPEN_QUOTES.has(ch)) openCount += 1;
56
+ }
57
+ if (openCount === 0) return "N";
58
+ if (RE_TRUE_SANDWICH.test(p)) return "S";
59
+ if (openCount >= 2) return "M";
60
+ if (OPEN_QUOTES.has(p[0])) return "Q";
61
+ return "A";
62
+ }
63
+
64
+ // 计算五类段落结构(N / A / Q / S / M)的香农熵
65
+ export function computeCadenceEntropy(types) {
66
+ if (!types || types.length === 0) return 0;
67
+ const counts = { N: 0, A: 0, Q: 0, S: 0, M: 0 };
68
+ for (const t of types) {
69
+ const key = counts[t] !== undefined ? t : "N";
70
+ counts[key] += 1;
71
+ }
72
+ const total = types.length;
73
+ let ent = 0;
74
+ for (const v of Object.values(counts)) {
75
+ if (v > 0) {
76
+ const p = v / total;
77
+ ent -= p * Math.log(p);
78
+ }
79
+ }
80
+ return Number(ent.toFixed(4));
81
+ }
82
+
83
+ // 扫描连续 >=6 个实词汉字无虚词缓冲硬拼成的修饰语砖块(每千字频次及样例)
84
+ export function measureCompoundBricks(text, exemptTerms = []) {
85
+ let masked = String(text || "");
86
+ for (const term of exemptTerms || []) {
87
+ if (term && term.length >= 2) {
88
+ masked = masked.split(term).join(" ");
89
+ }
90
+ }
91
+ const nh = Math.max(countHanChars(masked), 1);
92
+ let curLen = 0;
93
+ let buf = "";
94
+ let bricks = 0;
95
+ const samples = [];
96
+ for (const ch of masked) {
97
+ if (RE_HAN_SINGLE.test(ch) && !FUNC_CHAR_SET.has(ch)) {
98
+ curLen += 1;
99
+ buf += ch;
100
+ } else {
101
+ if (curLen >= 6) {
102
+ bricks += 1;
103
+ if (samples.length < 5) samples.push(buf);
104
+ }
105
+ curLen = 0;
106
+ buf = "";
107
+ }
108
+ }
109
+ if (curLen >= 6) {
110
+ bricks += 1;
111
+ if (samples.length < 5) samples.push(buf);
112
+ }
113
+ return {
114
+ bricks,
115
+ brickPer1k: Number(((bricks * 1000) / nh).toFixed(2)),
116
+ samples,
117
+ };
118
+ }
119
+
120
+ // 提取带原始行号的正文自然段列表(跳过空行、Markdown 标题与分隔线)
121
+ export function extractNumberedParagraphs(rawContent) {
122
+ const lines = String(rawContent || "").split(/\r?\n/u);
123
+ const out = [];
124
+ for (let idx = 0; idx < lines.length; idx += 1) {
125
+ const trimmed = lines[idx].trim();
126
+ if (!trimmed) continue;
127
+ if (trimmed.startsWith("#") || /^(?:-{3,}|\*{3,}|_{3,})$/u.test(trimmed)) continue;
128
+ const hanLen = countHanChars(trimmed);
129
+ if (hanLen === 0) continue;
130
+ out.push({
131
+ line: idx + 1,
132
+ text: trimmed,
133
+ hanLen,
134
+ cadenceType: classifyParagraphCadence(trimmed),
135
+ });
136
+ }
137
+ return out;
138
+ }
139
+
140
+ // 计算单个窗口的综合 AIGC 结构与词汇失衡分(基于实测 280 字分段样本校准,0.50 为黄标警戒线)
141
+ export function evaluateWindowSlice(paras, exemptTerms = []) {
142
+ const joined = paras.map((p) => p.text).join("\n");
143
+ const totalHan = Math.max(
144
+ paras.reduce((acc, p) => acc + p.hanLen, 0),
145
+ 1
146
+ );
147
+ const types = paras.map((p) => p.cadenceType);
148
+ const nPara = paras.length;
149
+ const sCount = types.filter((t) => t === "S").length;
150
+ const aCount = types.filter((t) => t === "A" || t === "M").length;
151
+ const nCount = types.filter((t) => t === "N").length;
152
+ const qCount = types.filter((t) => t === "Q").length;
153
+
154
+ const sandwichRatio = sCount / nPara;
155
+ const cadenceEntropy = computeCadenceEntropy(types);
156
+
157
+ // 统计连续夹心段与连续动作冒号段的最大连击数
158
+ let maxSandwichStreak = 0;
159
+ let maxActionColonStreak = 0;
160
+ let curS = 0;
161
+ let curA = 0;
162
+ for (const t of types) {
163
+ curS = t === "S" ? curS + 1 : 0;
164
+ curA = t === "A" ? curA + 1 : 0;
165
+ if (curS > maxSandwichStreak) maxSandwichStreak = curS;
166
+ if (curA > maxActionColonStreak) maxActionColonStreak = curA;
167
+ }
168
+
169
+ // 统计引号外叙述层的“这/那”与“的”,但以整窗有效汉字为分母,避免高对白段因叙述字数过少产生小分母放大误报
170
+ const dePer100 = Number(((countChar(joined, CH_DE) * 100) / totalHan).toFixed(2));
171
+ const narrationOnly = joined.replace(RE_QUOTE_SPAN, " ");
172
+ const narrHan = countHanChars(narrationOnly);
173
+ const narrDePer100 =
174
+ narrHan >= 80
175
+ ? Number(((countChar(narrationOnly, CH_DE) * 100) / narrHan).toFixed(2))
176
+ : dePer100;
177
+ const demonsPer100 = Number(
178
+ (
179
+ ((countChar(narrationOnly, CH_ZHE_DEM) + countChar(narrationOnly, CH_NA_DEM)) *
180
+ 100) /
181
+ totalHan
182
+ ).toFixed(2)
183
+ );
184
+
185
+ const quotedMatches = joined.match(RE_QUOTE_SPAN) || [];
186
+ const quotedHan = quotedMatches.reduce((acc, q) => acc + countHanChars(q), 0);
187
+ const quoteCharRatio = Number((quotedHan / totalHan).toFixed(3));
188
+
189
+ const sents = joined
190
+ .split(RE_SENT_SPLIT)
191
+ .map((s) => countHanChars(s))
192
+ .filter((len) => len > 0);
193
+ const sentMean =
194
+ sents.length > 0
195
+ ? Number((sents.reduce((a, b) => a + b, 0) / sents.length).toFixed(1))
196
+ : totalHan;
197
+ const paraMean = Number((totalHan / nPara).toFixed(1));
198
+
199
+ const periodQuoteMatches = joined.match(RE_PERIOD_BEFORE_QUOTE) || [];
200
+ const periodQuoteCount = periodQuoteMatches.length;
201
+
202
+ const rawBricks = measureCompoundBricks(narrationOnly, exemptTerms);
203
+ const brickSamples = rawBricks.samples;
204
+ const brickPer1k = Number(((rawBricks.bricks * 1000) / totalHan).toFixed(2));
205
+
206
+ // 双侧“的”字偏离惩罚:重点拦截 <1.20 的去味过猛脱水,仅在引号外叙述层 >3.60 时惩罚欧化定语堆叠
207
+ let dePenalty = 0;
208
+ if (dePer100 < 1.25) {
209
+ dePenalty = (1.25 - dePer100) * 0.055;
210
+ } else if (narrDePer100 > 3.6) {
211
+ dePenalty = (narrDePer100 - 3.6) * 0.035;
212
+ }
213
+
214
+ const sExcess = Math.max(0, sandwichRatio - 0.36);
215
+ const demExcess = Math.max(0, demonsPer100 - 1.15);
216
+ const brickExcess = Math.max(0, brickPer1k - 14.0);
217
+ const entDeficit = Math.max(0, 0.9 - cadenceEntropy);
218
+ const paraExcess = Math.max(0, paraMean - 82.0);
219
+ const sentExcess = Math.max(0, sentMean - 38.0);
220
+
221
+ const rawScore =
222
+ 0.382 +
223
+ dePenalty +
224
+ sExcess * 0.175 +
225
+ (maxSandwichStreak >= 3 ? (maxSandwichStreak - 2) * 0.038 : 0) +
226
+ (maxActionColonStreak >= 6 ? 0.045 : 0) +
227
+ demExcess * 0.048 +
228
+ brickExcess * 0.0032 +
229
+ entDeficit * 0.052 +
230
+ paraExcess * 0.001 +
231
+ sentExcess * 0.0025 +
232
+ periodQuoteCount * 0.045;
233
+
234
+ const estimatedRisk = Number(Math.min(0.95, Math.max(0.25, rawScore)).toFixed(4));
235
+
236
+ const reasons = [];
237
+ if (periodQuoteCount > 0) reasons.push("period_before_quote");
238
+ if (maxSandwichStreak >= 3 || sandwichRatio >= 0.5) reasons.push("sandwich_overload");
239
+ if (maxActionColonStreak >= 6) reasons.push("action_colon_wall");
240
+ if (nPara >= 4 && cadenceEntropy < 0.8) reasons.push("low_cadence_entropy");
241
+ if (dePer100 < 1.05 && (demonsPer100 > 1.15 || brickPer1k > 14)) {
242
+ reasons.push("de_starvation_rebound");
243
+ }
244
+ if (narrDePer100 > 3.6) reasons.push("excessive_de_density");
245
+ if (demonsPer100 > 1.45) reasons.push("demonstrative_spike");
246
+ if (brickPer1k > 18) reasons.push("compound_modifier_bricks");
247
+ if (paraMean > 90) reasons.push("oversized_paragraph_mean");
248
+
249
+ return {
250
+ startLine: paras[0].line,
251
+ endLine: paras[paras.length - 1].line,
252
+ paragraphCount: nPara,
253
+ hanChars: totalHan,
254
+ sequence: types.join(""),
255
+ estimatedRisk,
256
+ dePer100,
257
+ demonsPer100,
258
+ sandwichRatio: Number(sandwichRatio.toFixed(3)),
259
+ maxSandwichStreak,
260
+ maxActionColonStreak,
261
+ cadenceEntropy,
262
+ quoteCharRatio,
263
+ paraMean,
264
+ sentMean,
265
+ brickPer1k,
266
+ brickSamples,
267
+ periodQuoteCount,
268
+ reasons,
269
+ };
270
+ }
271
+
272
+ // 对整章执行滑窗 AIGC 结构与词汇风险扫描(默认 6 段一窗、步长 2 段,贴合 250-350 字检测粒度)
273
+ export function scanChapterAigcWindows(rawContent, options = {}) {
274
+ const paras = extractNumberedParagraphs(rawContent);
275
+ const threshold = options.threshold !== undefined ? Number(options.threshold) : 0.5;
276
+ const windowParas = options.windowParas || 6;
277
+ const stride = options.stride || 2;
278
+ const minWindowHan = options.minWindowHan || 180;
279
+ const exemptTerms = options.exemptTerms || [];
280
+
281
+ if (paras.length === 0) {
282
+ return {
283
+ pass: true,
284
+ threshold,
285
+ overallRisk: 0,
286
+ maxWindowRisk: 0,
287
+ worstWindow: null,
288
+ chapterCadence: {
289
+ sequence: "",
290
+ cadenceEntropy: 0,
291
+ sandwichRatio: 0,
292
+ maxSandwichStreak: 0,
293
+ maxActionColonStreak: 0,
294
+ demonsPer100Han: 0,
295
+ brickPer1kHan: 0,
296
+ },
297
+ windows: [],
298
+ flaggedWindows: [],
299
+ monotonySpans: [],
300
+ telegraphicSpans: [],
301
+ };
302
+ }
303
+
304
+ const chapterEval = evaluateWindowSlice(paras, exemptTerms);
305
+ const windows = [];
306
+ if (paras.length <= windowParas) {
307
+ windows.push(chapterEval);
308
+ } else {
309
+ for (let i = 0; i <= paras.length - windowParas; i += stride) {
310
+ const slice = paras.slice(i, i + windowParas);
311
+ const w = evaluateWindowSlice(slice, exemptTerms);
312
+ if (w.hanChars >= minWindowHan) windows.push(w);
313
+ }
314
+ // 确保章末最后 windowParas 段也被完整覆盖
315
+ if ((paras.length - windowParas) % stride !== 0) {
316
+ const tailSlice = paras.slice(paras.length - windowParas);
317
+ const tailW = evaluateWindowSlice(tailSlice, exemptTerms);
318
+ if (tailW.hanChars >= minWindowHan) windows.push(tailW);
319
+ }
320
+ }
321
+
322
+ let worstWindow = null;
323
+ for (const w of windows) {
324
+ if (!worstWindow || w.estimatedRisk > worstWindow.estimatedRisk) {
325
+ worstWindow = w;
326
+ }
327
+ }
328
+
329
+ const flaggedWindows = windows.filter((w) => w.estimatedRisk >= threshold);
330
+
331
+ // 提取全章级连续句式同构区间(S 连击 >= 4 或 A 连击 >= 8,用于默认审计高置信告警)
332
+ const monotonySpans = [];
333
+ let curType = "";
334
+ let streakStartIdx = 0;
335
+ let streakLen = 0;
336
+ const flushStreak = (endIdx) => {
337
+ if (
338
+ (curType === "S" && streakLen >= 4) ||
339
+ (curType === "A" && streakLen >= 8)
340
+ ) {
341
+ monotonySpans.push({
342
+ kind: curType === "S" ? "sandwich_quote_streak" : "action_colon_streak",
343
+ streak: streakLen,
344
+ startLine: paras[streakStartIdx].line,
345
+ endLine: paras[endIdx].line,
346
+ });
347
+ }
348
+ };
349
+ for (let i = 0; i < paras.length; i += 1) {
350
+ const t = paras[i].cadenceType;
351
+ if (t === curType) {
352
+ streakLen += 1;
353
+ } else {
354
+ if (streakLen > 0) flushStreak(i - 1);
355
+ curType = t;
356
+ streakStartIdx = i;
357
+ streakLen = 1;
358
+ }
359
+ }
360
+ if (streakLen > 0) flushStreak(paras.length - 1);
361
+
362
+ // 提取极端“去味反弹”脱水区间(的<0.95 且 叙述层指示词这/那>1.45 且 实词砖块>14)
363
+ const telegraphicSpans = windows.filter(
364
+ (w) => w.dePer100 < 0.95 && w.demonsPer100 > 1.45 && w.brickPer1k > 14
365
+ );
366
+
367
+ return {
368
+ pass: flaggedWindows.length === 0,
369
+ threshold,
370
+ overallRisk: chapterEval.estimatedRisk,
371
+ maxWindowRisk: worstWindow ? worstWindow.estimatedRisk : chapterEval.estimatedRisk,
372
+ worstWindow,
373
+ chapterCadence: {
374
+ sequence: chapterEval.sequence,
375
+ cadenceEntropy: chapterEval.cadenceEntropy,
376
+ sandwichRatio: chapterEval.sandwichRatio,
377
+ maxSandwichStreak: chapterEval.maxSandwichStreak,
378
+ maxActionColonStreak: chapterEval.maxActionColonStreak,
379
+ demonsPer100Han: chapterEval.demonsPer100,
380
+ brickPer1kHan: chapterEval.brickPer1k,
381
+ },
382
+ windows,
383
+ flaggedWindows,
384
+ monotonySpans,
385
+ telegraphicSpans,
386
+ };
387
+ }