inkbone 0.0.0-stage → 2.0.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.
- package/LICENSE +21 -0
- package/README.en.md +318 -0
- package/README.md +333 -2
- package/bin/inkbone.mjs +941 -0
- package/configs/genres.json +570 -0
- package/configs/messages.json +302 -0
- package/configs/platforms.json +62 -0
- package/configs/presets.json +265 -0
- package/configs/severity.json +52 -0
- package/configs/zh-linguistics.json +986 -0
- package/configs/zh-traditional.json +97 -0
- package/examples/claude-code-hooks.json +15 -0
- package/examples/mcp-config.json +12 -0
- package/package.json +61 -4
- package/prompts/00-style-architect.md +42 -0
- package/prompts/01-beat-planner.md +54 -0
- package/prompts/02-paratactic-renderer.md +60 -0
- package/prompts/03-targeted-rewriter.md +39 -0
- package/prompts/04-evidence-reviewer.md +39 -0
- package/prompts/05-reader-simulator.md +54 -0
- package/prompts/06-ledger-importer.md +41 -0
- package/prompts/07-chapter-settler.md +66 -0
- package/resources/bad_vs_good_cases.md +98 -0
- package/resources/eval/blind-read-instructions.md +18 -0
- package/resources/genre_playbooks/classical-xianxia.md +22 -0
- package/resources/genre_playbooks/general-clean.md +19 -0
- package/resources/genre_playbooks/historical-court.md +21 -0
- package/resources/genre_playbooks/light-fantasy.md +21 -0
- package/resources/genre_playbooks/mystery-thriller.md +22 -0
- package/resources/genre_playbooks/romance-emotional.md +20 -0
- package/resources/genre_playbooks/scifi-wasteland.md +21 -0
- package/resources/genre_playbooks/urban-realism.md +22 -0
- package/resources/genre_playbooks/wuxia-jianghu.md +21 -0
- package/resources/micro_techniques.md +77 -0
- package/skills/inkbone/LICENSE +21 -0
- package/skills/inkbone/README.md +334 -0
- package/skills/inkbone/SKILL.md +155 -0
- package/skills/inkbone/benchmarks/eval-set/README.md +49 -0
- package/skills/inkbone/benchmarks/eval-set/public-pairs.json +42 -0
- package/skills/inkbone/benchmarks/eval-set/seeds.json +42 -0
- package/skills/inkbone/bin/inkbone.mjs +941 -0
- package/skills/inkbone/configs/genres.json +570 -0
- package/skills/inkbone/configs/messages.json +302 -0
- package/skills/inkbone/configs/platforms.json +62 -0
- package/skills/inkbone/configs/presets.json +265 -0
- package/skills/inkbone/configs/severity.json +52 -0
- package/skills/inkbone/configs/zh-linguistics.json +986 -0
- package/skills/inkbone/configs/zh-traditional.json +97 -0
- package/skills/inkbone/package.json +63 -0
- package/skills/inkbone/prompts/00-style-architect.md +42 -0
- package/skills/inkbone/prompts/01-beat-planner.md +54 -0
- package/skills/inkbone/prompts/02-paratactic-renderer.md +60 -0
- package/skills/inkbone/prompts/03-targeted-rewriter.md +39 -0
- package/skills/inkbone/prompts/04-evidence-reviewer.md +39 -0
- package/skills/inkbone/prompts/05-reader-simulator.md +54 -0
- package/skills/inkbone/prompts/06-ledger-importer.md +41 -0
- package/skills/inkbone/prompts/07-chapter-settler.md +66 -0
- package/skills/inkbone/resources/bad_vs_good_cases.md +98 -0
- package/skills/inkbone/resources/eval/blind-read-instructions.md +18 -0
- package/skills/inkbone/resources/genre_playbooks/classical-xianxia.md +22 -0
- package/skills/inkbone/resources/genre_playbooks/general-clean.md +19 -0
- package/skills/inkbone/resources/genre_playbooks/historical-court.md +21 -0
- package/skills/inkbone/resources/genre_playbooks/light-fantasy.md +21 -0
- package/skills/inkbone/resources/genre_playbooks/mystery-thriller.md +22 -0
- package/skills/inkbone/resources/genre_playbooks/romance-emotional.md +20 -0
- package/skills/inkbone/resources/genre_playbooks/scifi-wasteland.md +21 -0
- package/skills/inkbone/resources/genre_playbooks/urban-realism.md +22 -0
- package/skills/inkbone/resources/genre_playbooks/wuxia-jianghu.md +21 -0
- package/skills/inkbone/resources/micro_techniques.md +77 -0
- package/skills/inkbone/src/auditor.mjs +24 -0
- package/skills/inkbone/src/benchmark-runner.mjs +71 -0
- package/skills/inkbone/src/boundary-compiler.mjs +54 -0
- package/skills/inkbone/src/browser-doctor.mjs +30 -0
- package/skills/inkbone/src/calibrator.mjs +175 -0
- package/skills/inkbone/src/config-loader.mjs +233 -0
- package/skills/inkbone/src/continuity.mjs +5 -0
- package/skills/inkbone/src/core/auditor.mjs +914 -0
- package/skills/inkbone/src/core/boundary-compiler.mjs +423 -0
- package/skills/inkbone/src/core/browser-doctor.mjs +318 -0
- package/skills/inkbone/src/core/config-compiler.mjs +434 -0
- package/skills/inkbone/src/core/continuity.mjs +158 -0
- package/skills/inkbone/src/core/evidence-validator.mjs +77 -0
- package/skills/inkbone/src/core/exporter.mjs +128 -0
- package/skills/inkbone/src/core/formatter.mjs +241 -0
- package/skills/inkbone/src/core/ledger-manager.mjs +576 -0
- package/skills/inkbone/src/core/normalizer.mjs +517 -0
- package/skills/inkbone/src/core/profiler.mjs +686 -0
- package/skills/inkbone/src/core/rule-engine.mjs +1536 -0
- package/skills/inkbone/src/core/style-profiler.mjs +229 -0
- package/skills/inkbone/src/detector.mjs +270 -0
- package/skills/inkbone/src/doctor.mjs +428 -0
- package/skills/inkbone/src/evaluation.mjs +311 -0
- package/skills/inkbone/src/evidence-validator.mjs +15 -0
- package/skills/inkbone/src/exporter.mjs +106 -0
- package/skills/inkbone/src/formatter.mjs +34 -0
- package/skills/inkbone/src/importer.mjs +230 -0
- package/skills/inkbone/src/index.mjs +116 -0
- package/skills/inkbone/src/ledger-manager.mjs +15 -0
- package/skills/inkbone/src/mcp-server.mjs +861 -0
- package/skills/inkbone/src/normalizer.mjs +73 -0
- package/skills/inkbone/src/profiler.mjs +17 -0
- package/skills/inkbone/src/rule-engine.mjs +73 -0
- package/skills/inkbone/src/rule-stats.mjs +142 -0
- package/skills/inkbone/src/style-profiler.mjs +25 -0
- package/src/auditor.mjs +24 -0
- package/src/benchmark-runner.mjs +71 -0
- package/src/boundary-compiler.mjs +54 -0
- package/src/browser-doctor.mjs +30 -0
- package/src/calibrator.mjs +175 -0
- package/src/config-loader.mjs +233 -0
- package/src/continuity.mjs +5 -0
- package/src/core/auditor.mjs +914 -0
- package/src/core/boundary-compiler.mjs +423 -0
- package/src/core/browser-doctor.mjs +318 -0
- package/src/core/config-compiler.mjs +434 -0
- package/src/core/continuity.mjs +158 -0
- package/src/core/evidence-validator.mjs +77 -0
- package/src/core/exporter.mjs +128 -0
- package/src/core/formatter.mjs +241 -0
- package/src/core/ledger-manager.mjs +576 -0
- package/src/core/normalizer.mjs +517 -0
- package/src/core/profiler.mjs +686 -0
- package/src/core/rule-engine.mjs +1536 -0
- package/src/core/style-profiler.mjs +229 -0
- package/src/detector.mjs +270 -0
- package/src/doctor.mjs +428 -0
- package/src/evaluation.mjs +311 -0
- package/src/evidence-validator.mjs +15 -0
- package/src/exporter.mjs +106 -0
- package/src/formatter.mjs +34 -0
- package/src/importer.mjs +230 -0
- package/src/index.mjs +116 -0
- package/src/ledger-manager.mjs +15 -0
- package/src/mcp-server.mjs +861 -0
- package/src/normalizer.mjs +73 -0
- package/src/profiler.mjs +17 -0
- package/src/rule-engine.mjs +73 -0
- package/src/rule-stats.mjs +142 -0
- package/src/style-profiler.mjs +25 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
// 纯内存配置编译模块(零文件系统依赖,供 Node 端与浏览器静态试跑页共用)
|
|
2
|
+
|
|
3
|
+
// 把规则数组预编译为全局正则,并标注规则所属层级(universal / genre / project)
|
|
4
|
+
export function compileRules(rules, layer, defaultScope = "all") {
|
|
5
|
+
return (rules || []).map((rule) => ({
|
|
6
|
+
...rule,
|
|
7
|
+
layer,
|
|
8
|
+
scope: rule.scope || defaultScope,
|
|
9
|
+
window: rule.window || "all",
|
|
10
|
+
regex: new RegExp(rule.pattern, "gu"),
|
|
11
|
+
prevExcludeSet: rule.prevExcludeChars ? new Set(rule.prevExcludeChars) : null,
|
|
12
|
+
affirmationParticleSet: rule.affirmationParticles
|
|
13
|
+
? new Set(rule.affirmationParticles)
|
|
14
|
+
: null,
|
|
15
|
+
affirmationBoundarySet: rule.affirmationBoundaries
|
|
16
|
+
? new Set(rule.affirmationBoundaries)
|
|
17
|
+
: null,
|
|
18
|
+
nextIgnoreRegexObj: rule.nextIgnoreRegex
|
|
19
|
+
? new RegExp(rule.nextIgnoreRegex, "u")
|
|
20
|
+
: null,
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 预编译修辞密度与模型退化检测配置的正则表达式
|
|
25
|
+
function compileAuxiliaryRules(raw) {
|
|
26
|
+
const densityRaw = raw.densityRules || {};
|
|
27
|
+
const compiledDensity = {
|
|
28
|
+
tailWindowChars: densityRaw.tailWindowChars || 600,
|
|
29
|
+
microActionTic: densityRaw.microActionTic
|
|
30
|
+
? {
|
|
31
|
+
...densityRaw.microActionTic,
|
|
32
|
+
regex: new RegExp(densityRaw.microActionTic.pattern, "gu"),
|
|
33
|
+
}
|
|
34
|
+
: null,
|
|
35
|
+
stockReactionTic: densityRaw.stockReactionTic
|
|
36
|
+
? {
|
|
37
|
+
...densityRaw.stockReactionTic,
|
|
38
|
+
regexes: (densityRaw.stockReactionTic.patterns || []).map(
|
|
39
|
+
(p) => new RegExp(p, "gu")
|
|
40
|
+
),
|
|
41
|
+
}
|
|
42
|
+
: null,
|
|
43
|
+
actionListTic: densityRaw.actionListTic
|
|
44
|
+
? {
|
|
45
|
+
...densityRaw.actionListTic,
|
|
46
|
+
verbRegex: new RegExp(densityRaw.actionListTic.verbPattern, "gu"),
|
|
47
|
+
separatorRegex: new RegExp(
|
|
48
|
+
densityRaw.actionListTic.separatorPattern,
|
|
49
|
+
"gu"
|
|
50
|
+
),
|
|
51
|
+
}
|
|
52
|
+
: null,
|
|
53
|
+
quoteEmphasisTic: densityRaw.quoteEmphasisTic
|
|
54
|
+
? {
|
|
55
|
+
...densityRaw.quoteEmphasisTic,
|
|
56
|
+
speechVerbRegex: new RegExp(
|
|
57
|
+
densityRaw.quoteEmphasisTic.speechVerbPattern,
|
|
58
|
+
"u"
|
|
59
|
+
),
|
|
60
|
+
punctuationInsideRegex: new RegExp(
|
|
61
|
+
densityRaw.quoteEmphasisTic.punctuationInsidePattern,
|
|
62
|
+
"u"
|
|
63
|
+
),
|
|
64
|
+
onomatopoeiaSuffixRegex: new RegExp(
|
|
65
|
+
densityRaw.quoteEmphasisTic.onomatopoeiaSuffixPattern,
|
|
66
|
+
"u"
|
|
67
|
+
),
|
|
68
|
+
}
|
|
69
|
+
: null,
|
|
70
|
+
metaphorDensityTic: densityRaw.metaphorDensityTic
|
|
71
|
+
? {
|
|
72
|
+
...densityRaw.metaphorDensityTic,
|
|
73
|
+
markerRegex: new RegExp(densityRaw.metaphorDensityTic.markerPattern, "gu"),
|
|
74
|
+
likePhraseRegex: new RegExp(
|
|
75
|
+
densityRaw.metaphorDensityTic.likePhrasePattern,
|
|
76
|
+
"gu"
|
|
77
|
+
),
|
|
78
|
+
prefixGuardRegex: new RegExp(
|
|
79
|
+
densityRaw.metaphorDensityTic.prefixGuardPattern,
|
|
80
|
+
"u"
|
|
81
|
+
),
|
|
82
|
+
}
|
|
83
|
+
: null,
|
|
84
|
+
abstractSummaryTic: densityRaw.abstractSummaryTic
|
|
85
|
+
? {
|
|
86
|
+
...densityRaw.abstractSummaryTic,
|
|
87
|
+
regexes: (densityRaw.abstractSummaryTic.patterns || []).map(
|
|
88
|
+
(p) => new RegExp(p, "gu")
|
|
89
|
+
),
|
|
90
|
+
}
|
|
91
|
+
: null,
|
|
92
|
+
reasoningChainTic: densityRaw.reasoningChainTic
|
|
93
|
+
? {
|
|
94
|
+
...densityRaw.reasoningChainTic,
|
|
95
|
+
compiledPatterns: (densityRaw.reasoningChainTic.patterns || []).map(
|
|
96
|
+
(item) => ({
|
|
97
|
+
...item,
|
|
98
|
+
regex: new RegExp(item.pattern, "gu"),
|
|
99
|
+
})
|
|
100
|
+
),
|
|
101
|
+
}
|
|
102
|
+
: null,
|
|
103
|
+
ellipsisDensityTic: densityRaw.ellipsisDensityTic
|
|
104
|
+
? {
|
|
105
|
+
...densityRaw.ellipsisDensityTic,
|
|
106
|
+
regex: new RegExp(densityRaw.ellipsisDensityTic.pattern, "gu"),
|
|
107
|
+
}
|
|
108
|
+
: null,
|
|
109
|
+
exclamationDensityTic: densityRaw.exclamationDensityTic
|
|
110
|
+
? {
|
|
111
|
+
...densityRaw.exclamationDensityTic,
|
|
112
|
+
regex: new RegExp(densityRaw.exclamationDensityTic.pattern, "gu"),
|
|
113
|
+
}
|
|
114
|
+
: null,
|
|
115
|
+
exclamationStackTic: densityRaw.exclamationStackTic
|
|
116
|
+
? {
|
|
117
|
+
...densityRaw.exclamationStackTic,
|
|
118
|
+
regex: new RegExp(densityRaw.exclamationStackTic.pattern, "gu"),
|
|
119
|
+
}
|
|
120
|
+
: null,
|
|
121
|
+
overcompressedProseTic: densityRaw.overcompressedProseTic
|
|
122
|
+
? {
|
|
123
|
+
...densityRaw.overcompressedProseTic,
|
|
124
|
+
particleRegex: new RegExp(
|
|
125
|
+
densityRaw.overcompressedProseTic.particlePattern,
|
|
126
|
+
"gu"
|
|
127
|
+
),
|
|
128
|
+
panelLineRegex: new RegExp(
|
|
129
|
+
densityRaw.overcompressedProseTic.panelLinePattern,
|
|
130
|
+
"u"
|
|
131
|
+
),
|
|
132
|
+
}
|
|
133
|
+
: null,
|
|
134
|
+
lowConnectiveDensityTic: densityRaw.lowConnectiveDensityTic || null,
|
|
135
|
+
dialogueOnlyStreakTic: densityRaw.dialogueOnlyStreakTic
|
|
136
|
+
? {
|
|
137
|
+
...densityRaw.dialogueOnlyStreakTic,
|
|
138
|
+
quoteLineRegex: new RegExp(
|
|
139
|
+
densityRaw.dialogueOnlyStreakTic.quoteLinePattern,
|
|
140
|
+
"u"
|
|
141
|
+
),
|
|
142
|
+
}
|
|
143
|
+
: null,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const degenRaw = raw.degeneration || {};
|
|
147
|
+
const compiledDegeneration = degenRaw.placeholderRules
|
|
148
|
+
? {
|
|
149
|
+
...degenRaw,
|
|
150
|
+
sentenceSplitRegex: new RegExp(degenRaw.sentenceSplitRegex, "u"),
|
|
151
|
+
chapterHeadingRegex: new RegExp(degenRaw.chapterHeadingRegex, "u"),
|
|
152
|
+
endSignoffRegex: new RegExp(degenRaw.endSignoffRegex, "iu"),
|
|
153
|
+
dividerRegex: new RegExp(degenRaw.dividerRegex, "u"),
|
|
154
|
+
trailingMarkdownStripRegex: new RegExp(
|
|
155
|
+
degenRaw.trailingMarkdownStripRegex,
|
|
156
|
+
"u"
|
|
157
|
+
),
|
|
158
|
+
terminalPunctuationRegex: new RegExp(
|
|
159
|
+
degenRaw.terminalPunctuationRegex,
|
|
160
|
+
"u"
|
|
161
|
+
),
|
|
162
|
+
placeholderRules: (degenRaw.placeholderRules || []).map((rule) => ({
|
|
163
|
+
...rule,
|
|
164
|
+
layer: "universal",
|
|
165
|
+
regex: new RegExp(rule.pattern, "u"),
|
|
166
|
+
})),
|
|
167
|
+
metaLeakTier1Regex: degenRaw.metaLeakTier1Pattern
|
|
168
|
+
? new RegExp(degenRaw.metaLeakTier1Pattern, "gu")
|
|
169
|
+
: null,
|
|
170
|
+
metaLeakTier2Regex: degenRaw.metaLeakTier2Pattern
|
|
171
|
+
? new RegExp(degenRaw.metaLeakTier2Pattern, "gu")
|
|
172
|
+
: null,
|
|
173
|
+
}
|
|
174
|
+
: null;
|
|
175
|
+
|
|
176
|
+
const crossRaw = raw.crossParagraphParallel || null;
|
|
177
|
+
const compiledCrossParallel = crossRaw
|
|
178
|
+
? {
|
|
179
|
+
...crossRaw,
|
|
180
|
+
startRegexObj: new RegExp(crossRaw.startRegex, "u"),
|
|
181
|
+
middleRegexObj: new RegExp(crossRaw.middleRegex, "u"),
|
|
182
|
+
endRegexObj: new RegExp(crossRaw.endRegex, "u"),
|
|
183
|
+
}
|
|
184
|
+
: null;
|
|
185
|
+
|
|
186
|
+
const charExtRaw = raw.characterExtraction || null;
|
|
187
|
+
const compiledCharExtraction = charExtRaw
|
|
188
|
+
? {
|
|
189
|
+
...charExtRaw,
|
|
190
|
+
surnameSet: new Set(charExtRaw.commonSurnames || []),
|
|
191
|
+
compoundSurnames: [...(charExtRaw.compoundSurnames || [])].sort(
|
|
192
|
+
(a, b) => b.length - a.length
|
|
193
|
+
),
|
|
194
|
+
titleSuffixes: [...(charExtRaw.titleSuffixes || [])].sort(
|
|
195
|
+
(a, b) => b.length - a.length
|
|
196
|
+
),
|
|
197
|
+
stopwordSet: new Set([
|
|
198
|
+
...(raw.commonTwoCharStopwords || []),
|
|
199
|
+
...(charExtRaw.nonPersonStopwords || []),
|
|
200
|
+
]),
|
|
201
|
+
speechActionRegex:
|
|
202
|
+
charExtRaw.boundaryLeadPattern && charExtRaw.speechActionPattern
|
|
203
|
+
? new RegExp(
|
|
204
|
+
`${charExtRaw.boundaryLeadPattern}([\\p{Script=Han}]{2,4})(?=${charExtRaw.speechActionPattern})`,
|
|
205
|
+
"gu"
|
|
206
|
+
)
|
|
207
|
+
: null,
|
|
208
|
+
}
|
|
209
|
+
: null;
|
|
210
|
+
|
|
211
|
+
const stateGuardRaw = raw.characterStateGuard || null;
|
|
212
|
+
const compiledStateGuard = stateGuardRaw
|
|
213
|
+
? {
|
|
214
|
+
inactiveStatuses: new Set(stateGuardRaw.inactiveStatuses || ["deceased", "dead", "exited"]),
|
|
215
|
+
flashbackRegex: stateGuardRaw.flashbackPattern
|
|
216
|
+
? new RegExp(stateGuardRaw.flashbackPattern, "u")
|
|
217
|
+
: null,
|
|
218
|
+
activeVerbPattern: stateGuardRaw.activeVerbPattern || "",
|
|
219
|
+
}
|
|
220
|
+
: null;
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
compiledDensity,
|
|
224
|
+
compiledDegeneration,
|
|
225
|
+
compiledCrossParallel,
|
|
226
|
+
compiledCharExtraction,
|
|
227
|
+
compiledStateGuard,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// 从解析后的 JSON 对象编译中文计算语言学配置与正则表达式
|
|
232
|
+
export function compileLinguisticsConfig(raw) {
|
|
233
|
+
const aux = compileAuxiliaryRules(raw);
|
|
234
|
+
return {
|
|
235
|
+
...raw,
|
|
236
|
+
compiledRegex: {
|
|
237
|
+
hanCharGlobal: new RegExp(raw.regex.hanChar, "gu"),
|
|
238
|
+
visibleCharGlobal: raw.regex.visibleChar
|
|
239
|
+
? new RegExp(raw.regex.visibleChar, "gu")
|
|
240
|
+
: new RegExp(raw.regex.hanChar, "gu"),
|
|
241
|
+
sentenceDelimiter: new RegExp(raw.regex.sentenceDelimiter, "u"),
|
|
242
|
+
quoteCharsGlobal: new RegExp(raw.regex.quoteChars, "gu"),
|
|
243
|
+
dialogueSpanGlobal: new RegExp(raw.regex.dialogueSpan, "gu"),
|
|
244
|
+
cornerQuoteDialogue: raw.regex.cornerQuoteDialogue
|
|
245
|
+
? {
|
|
246
|
+
cornerChars: new Set(raw.regex.cornerQuoteDialogue.cornerChars || []),
|
|
247
|
+
innerPunctRegex: raw.regex.cornerQuoteDialogue.innerPunctPattern
|
|
248
|
+
? new RegExp(raw.regex.cornerQuoteDialogue.innerPunctPattern, "u")
|
|
249
|
+
: null,
|
|
250
|
+
leadSpeechRegex: raw.regex.cornerQuoteDialogue.leadSpeechPattern
|
|
251
|
+
? new RegExp(raw.regex.cornerQuoteDialogue.leadSpeechPattern, "u")
|
|
252
|
+
: null,
|
|
253
|
+
}
|
|
254
|
+
: null,
|
|
255
|
+
quoteMaskRegexes: (raw.regex.quoteMaskPatterns || []).map(
|
|
256
|
+
(p) => new RegExp(p, "gu")
|
|
257
|
+
),
|
|
258
|
+
unclosedQuoteStart: raw.regex.unclosedQuoteStart
|
|
259
|
+
? new RegExp(raw.regex.unclosedQuoteStart, "u")
|
|
260
|
+
: null,
|
|
261
|
+
nonDialogueRhetoricalQuestion: new RegExp(
|
|
262
|
+
raw.regex.nonDialogueRhetoricalQuestion,
|
|
263
|
+
"u"
|
|
264
|
+
),
|
|
265
|
+
nestedDeChainGlobal: new RegExp(raw.regex.nestedDeChain, "gu"),
|
|
266
|
+
ledgerBracketNoteGlobal: new RegExp(raw.regex.ledgerBracketNote, "gu"),
|
|
267
|
+
bookTitleTermGlobal: new RegExp(raw.regex.bookTitleTerm, "gu"),
|
|
268
|
+
pronounHeadLine: raw.regex.pronounHeadLine
|
|
269
|
+
? new RegExp(raw.regex.pronounHeadLine, "u")
|
|
270
|
+
: null,
|
|
271
|
+
clauseSplitterForNgram: new RegExp(raw.regex.clauseSplitterForNgram, "u"),
|
|
272
|
+
quantifierNoiseFragment: new RegExp(
|
|
273
|
+
raw.regex.quantifierNoiseFragment,
|
|
274
|
+
"u"
|
|
275
|
+
),
|
|
276
|
+
twoCharStopwordSet: new Set(raw.commonTwoCharStopwords || []),
|
|
277
|
+
forbiddenCliches: compileRules(
|
|
278
|
+
raw.forbiddenCliches,
|
|
279
|
+
"universal",
|
|
280
|
+
"narration"
|
|
281
|
+
),
|
|
282
|
+
symmetricSkeletons: compileRules(
|
|
283
|
+
raw.symmetricSkeletons,
|
|
284
|
+
"universal",
|
|
285
|
+
"narration"
|
|
286
|
+
),
|
|
287
|
+
rhetoricalRules: compileRules(
|
|
288
|
+
raw.rhetoricalRules,
|
|
289
|
+
"universal",
|
|
290
|
+
"narration"
|
|
291
|
+
),
|
|
292
|
+
dialogueHygieneRules: compileRules(
|
|
293
|
+
raw.dialogueHygieneRules,
|
|
294
|
+
"universal",
|
|
295
|
+
"all"
|
|
296
|
+
),
|
|
297
|
+
crossParagraphParallel: aux.compiledCrossParallel,
|
|
298
|
+
densityRules: aux.compiledDensity,
|
|
299
|
+
degeneration: aux.compiledDegeneration,
|
|
300
|
+
characterExtraction: aux.compiledCharExtraction,
|
|
301
|
+
characterStateGuard: aux.compiledStateGuard,
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 从解析后的 JSON 对象编译繁体中文 / 港台网文规则层与繁简自动识别词表
|
|
307
|
+
export function compileTraditionalConfig(raw) {
|
|
308
|
+
if (!raw || typeof raw !== "object") return null;
|
|
309
|
+
const det = raw.detection || {};
|
|
310
|
+
return {
|
|
311
|
+
...raw,
|
|
312
|
+
detectionCompiled: {
|
|
313
|
+
minMarkerHits: det.minMarkerHits ?? 2,
|
|
314
|
+
minTraditionalRatio: det.minTraditionalRatio ?? 0.6,
|
|
315
|
+
tradSet: new Set(Array.from(det.traditionalMarkers || "")),
|
|
316
|
+
simpSet: new Set(Array.from(det.simplifiedMarkers || "")),
|
|
317
|
+
},
|
|
318
|
+
compiledClicheRules: compileRules(raw.forbiddenCliches, "universal", "narration"),
|
|
319
|
+
compiledRegisterRules: compileRules(raw.registerRules, "universal", "all"),
|
|
320
|
+
compiledDialogueHygieneRules: compileRules(raw.dialogueHygieneRules, "universal", "all"),
|
|
321
|
+
compiledFillerRules: compileRules(raw.fillerRules, "universal", "all"),
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// 零依赖判断输入文本属于简体中文(zh-hans)还是繁体中文(zh-hant)
|
|
326
|
+
export function detectScriptVariant(text, compiledTraditional) {
|
|
327
|
+
const det = compiledTraditional?.detectionCompiled;
|
|
328
|
+
if (!det || !text) return "zh-hans";
|
|
329
|
+
let tradHits = 0;
|
|
330
|
+
let simpHits = 0;
|
|
331
|
+
for (const ch of String(text)) {
|
|
332
|
+
if (det.tradSet.has(ch)) tradHits += 1;
|
|
333
|
+
else if (det.simpSet.has(ch)) simpHits += 1;
|
|
334
|
+
}
|
|
335
|
+
const total = tradHits + simpHits;
|
|
336
|
+
if (tradHits >= det.minMarkerHits && total > 0 && tradHits / total >= det.minTraditionalRatio) {
|
|
337
|
+
return "zh-hant";
|
|
338
|
+
}
|
|
339
|
+
return "zh-hans";
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 从解析后的 JSON 对象编译多题材语域防火墙配置
|
|
343
|
+
export function compileGenresConfig(raw) {
|
|
344
|
+
const compiledUniversalFillers = compileRules(
|
|
345
|
+
raw.universalFillerRules,
|
|
346
|
+
"universal",
|
|
347
|
+
"all"
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
const compiledGenres = {};
|
|
351
|
+
for (const [id, pack] of Object.entries(raw.genres || {})) {
|
|
352
|
+
compiledGenres[id] = {
|
|
353
|
+
...pack,
|
|
354
|
+
compiledRegisterRules: compileRules(pack.registerRules, "genre", "all"),
|
|
355
|
+
compiledClicheRules: compileRules(
|
|
356
|
+
pack.clicheRules,
|
|
357
|
+
"genre",
|
|
358
|
+
"narration"
|
|
359
|
+
),
|
|
360
|
+
compiledFillerRules: compileRules(pack.fillerRules, "genre", "all"),
|
|
361
|
+
compiledRhetoricalRules: compileRules(
|
|
362
|
+
pack.rhetoricalRules,
|
|
363
|
+
"genre",
|
|
364
|
+
"narration"
|
|
365
|
+
),
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return {
|
|
370
|
+
...raw,
|
|
371
|
+
compiledUniversalFillers,
|
|
372
|
+
genres: compiledGenres,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// 从解析后的 JSON 对象编译违规码分级映射
|
|
377
|
+
export function compileSeverityConfig(raw) {
|
|
378
|
+
const byCode = new Map();
|
|
379
|
+
for (const [level, codes] of Object.entries(raw.levels || {})) {
|
|
380
|
+
for (const code of codes) byCode.set(code, level);
|
|
381
|
+
}
|
|
382
|
+
return { byCode, defaultLevel: raw.defaultLevel || "warning" };
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// 从已编译的题材配置对象中解析指定题材包
|
|
386
|
+
export function resolveGenreFromConfig(genresConfig, genreName) {
|
|
387
|
+
const key = genreName || genresConfig.defaultGenre;
|
|
388
|
+
const pack = genresConfig.genres[key];
|
|
389
|
+
if (!pack) {
|
|
390
|
+
const validKeys = Object.keys(genresConfig.genres).join(", ");
|
|
391
|
+
throw new Error(`Unknown genre "${key}". Available genres: ${validKeys}`);
|
|
392
|
+
}
|
|
393
|
+
return pack;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// 从预设配置对象中解析指定阈值预设
|
|
397
|
+
export function resolvePresetFromConfig(presetsConfig, presetName) {
|
|
398
|
+
const key = presetName || presetsConfig.defaultPreset;
|
|
399
|
+
const preset = presetsConfig.presets[key];
|
|
400
|
+
if (!preset) {
|
|
401
|
+
const validKeys = Object.keys(presetsConfig.presets).join(", ");
|
|
402
|
+
throw new Error(`Unknown preset "${key}". Available presets: ${validKeys}`);
|
|
403
|
+
}
|
|
404
|
+
return preset;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// 把一份项目规则对象编译为可直接参与扫描的规则层
|
|
408
|
+
export function compileProjectRules(rawRules = {}) {
|
|
409
|
+
const literals = Array.from(
|
|
410
|
+
new Set(
|
|
411
|
+
(rawRules.whitelistLiterals || [])
|
|
412
|
+
.map((item) => String(item).trim())
|
|
413
|
+
.filter(Boolean)
|
|
414
|
+
)
|
|
415
|
+
).sort((a, b) => b.length - a.length);
|
|
416
|
+
|
|
417
|
+
return {
|
|
418
|
+
clicheRules: compileRules(rawRules.clicheRules, "project", "narration"),
|
|
419
|
+
fillerRules: compileRules(rawRules.fillerRules, "project", "all"),
|
|
420
|
+
registerRules: compileRules(rawRules.registerRules, "project", "all"),
|
|
421
|
+
symmetricSkeletons: compileRules(
|
|
422
|
+
rawRules.symmetricSkeletons,
|
|
423
|
+
"project",
|
|
424
|
+
"narration"
|
|
425
|
+
),
|
|
426
|
+
rhetoricalRules: compileRules(
|
|
427
|
+
rawRules.rhetoricalRules,
|
|
428
|
+
"project",
|
|
429
|
+
"narration"
|
|
430
|
+
),
|
|
431
|
+
disabledRuleIds: new Set(rawRules.disabledRuleIds || []),
|
|
432
|
+
whitelistLiterals: literals,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// 主语连续性检查:找出省略主语后可能被读成别人动作的句子,以及连续多段同一种起头方式
|
|
2
|
+
// 只在提供了人物名单(台账 characterNames / protagonist)时运行;所有中文词表都在 zh-linguistics.json 的 subjectContinuity 里
|
|
3
|
+
import { stripSpokenDialogue } from "./rule-engine.mjs";
|
|
4
|
+
|
|
5
|
+
// 把配置里的词表编译成按长度降序的数组,保证长名字优先匹配
|
|
6
|
+
function sortByLengthDesc(list) {
|
|
7
|
+
return [...new Set((list || []).filter(Boolean))].sort((a, b) => b.length - a.length);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 返回文本开头匹配到的第一个词(允许前面有空白),否则返回 null
|
|
11
|
+
function leadingToken(text, tokens) {
|
|
12
|
+
const trimmed = text.replace(/^\s+/u, "");
|
|
13
|
+
for (const token of tokens) {
|
|
14
|
+
if (trimmed.startsWith(token)) return token;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 判断文本里是否出现任一词
|
|
20
|
+
function containsAny(text, tokens) {
|
|
21
|
+
for (const token of tokens) {
|
|
22
|
+
if (text.includes(token)) return token;
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 从台账收集人物名与主角名(含别名字段)
|
|
28
|
+
export function collectCharacterNames(ledger, extraNames = []) {
|
|
29
|
+
const names = [...(ledger?.characterNames || []), ...extraNames];
|
|
30
|
+
const protagonist = new Set();
|
|
31
|
+
const p = ledger?.protagonist;
|
|
32
|
+
if (p && typeof p === "object") {
|
|
33
|
+
for (const [key, value] of Object.entries(p)) {
|
|
34
|
+
if (typeof value !== "string") continue;
|
|
35
|
+
if (key === "name" || /alias/iu.test(key)) {
|
|
36
|
+
protagonist.add(value);
|
|
37
|
+
names.push(value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { names: sortByLengthDesc(names), protagonistNames: protagonist };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 对单句做分类:开头是人名 / 代词 / 先动作后补主语 / 无主语动作 / 其他
|
|
45
|
+
function classifySentence(sentence, ctx) {
|
|
46
|
+
const clauses = sentence.split(ctx.clauseSplitter).filter((c) => c.trim().length > 0);
|
|
47
|
+
const first = clauses[0] || "";
|
|
48
|
+
const leadName = leadingToken(sentence, ctx.names);
|
|
49
|
+
if (leadName) return { kind: "name", actor: leadName, clauseIndex: 0 };
|
|
50
|
+
const leadPronoun = leadingToken(sentence, ctx.pronouns);
|
|
51
|
+
if (leadPronoun) return { kind: "pronoun", actor: null };
|
|
52
|
+
const firstHasRef = containsAny(first, ctx.names) || containsAny(first, ctx.pronouns);
|
|
53
|
+
if (!firstHasRef && leadingToken(first, ctx.actionLeads)) {
|
|
54
|
+
// 先写动作、再补主语:首个小句以动作开头且没有人名,随后某个小句以人名起头
|
|
55
|
+
for (let i = 1; i < Math.min(clauses.length, ctx.maxDelayedClauses + 1); i += 1) {
|
|
56
|
+
const name = leadingToken(clauses[i], ctx.names);
|
|
57
|
+
if (name) return { kind: "delayed", actor: name, clauseIndex: i };
|
|
58
|
+
if (containsAny(clauses[i], ctx.names) || containsAny(clauses[i], ctx.pronouns)) break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const anyRef = containsAny(sentence, ctx.names) || containsAny(sentence, ctx.pronouns);
|
|
62
|
+
if (!anyRef && leadingToken(sentence, ctx.actionLeads)) {
|
|
63
|
+
return { kind: "subjectless", actor: null };
|
|
64
|
+
}
|
|
65
|
+
return { kind: "other", actor: null };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 逐段逐句扫描主语连续性
|
|
69
|
+
export function scanSubjectContinuity(paragraphs, lingConfig, options = {}) {
|
|
70
|
+
const sc = lingConfig.subjectContinuity || {};
|
|
71
|
+
const names = sortByLengthDesc(options.names || []);
|
|
72
|
+
const result = { enabled: false, ambiguityHits: [], openingStreaks: [] };
|
|
73
|
+
if (names.length === 0 || !paragraphs || paragraphs.length === 0) return result;
|
|
74
|
+
result.enabled = true;
|
|
75
|
+
|
|
76
|
+
const protagonistNames = options.protagonistNames || new Set();
|
|
77
|
+
const ctx = {
|
|
78
|
+
names,
|
|
79
|
+
pronouns: sortByLengthDesc(sc.pronouns || []),
|
|
80
|
+
actionLeads: sortByLengthDesc(sc.actionLeads || []),
|
|
81
|
+
clauseSplitter: new RegExp(sc.clauseSplitter || "[,,;;::]", "u"),
|
|
82
|
+
maxDelayedClauses: sc.maxDelayedClauses || 4,
|
|
83
|
+
};
|
|
84
|
+
const sentenceSplitter = new RegExp(`(?<=[${sc.sentenceEndChars || "。!?!?…"}])`, "u");
|
|
85
|
+
const maxSame = sc.maxSameOpening || 3;
|
|
86
|
+
const streakKinds = new Set(sc.streakKinds || ["delayed", "subjectless", "protagonist"]);
|
|
87
|
+
|
|
88
|
+
let prevActor = null;
|
|
89
|
+
let prevActorText = "";
|
|
90
|
+
let prevActorPara = -1;
|
|
91
|
+
const maxActorClause = sc.maxActorClauseIndex ?? 2;
|
|
92
|
+
let streakKind = null;
|
|
93
|
+
let streakLines = [];
|
|
94
|
+
const flushStreak = () => {
|
|
95
|
+
if (streakKind && streakLines.length >= maxSame) {
|
|
96
|
+
result.openingStreaks.push({
|
|
97
|
+
kind: streakKind,
|
|
98
|
+
startLine: streakLines[0].line,
|
|
99
|
+
endLine: streakLines[streakLines.length - 1].line,
|
|
100
|
+
streak: streakLines.length,
|
|
101
|
+
samples: streakLines.slice(0, 3).map((s) => s.preview),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
paragraphs.forEach((para, paraIdx) => {
|
|
107
|
+
const dialogueInfo = stripSpokenDialogue(para.text, lingConfig, " ");
|
|
108
|
+
const hasDialogue = dialogueInfo.hasSpokenDialogue;
|
|
109
|
+
const narration = dialogueInfo.narration.trim();
|
|
110
|
+
if (!/\p{Script=Han}/u.test(narration)) {
|
|
111
|
+
// 纯对白段:重置主语链,不打断起头方式的连击计数
|
|
112
|
+
prevActor = null;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const sentences = narration
|
|
116
|
+
.split(sentenceSplitter)
|
|
117
|
+
.map((s) => s.trim())
|
|
118
|
+
.filter((s) => /\p{Script=Han}/u.test(s));
|
|
119
|
+
|
|
120
|
+
sentences.forEach((sentence, idx) => {
|
|
121
|
+
const cls = classifySentence(sentence, ctx);
|
|
122
|
+
if (idx === 0) {
|
|
123
|
+
// 起头方式连击:只统计每段第一句
|
|
124
|
+
let kind = cls.kind;
|
|
125
|
+
if (kind === "name") kind = protagonistNames.has(cls.actor) ? "protagonist" : "other";
|
|
126
|
+
if (streakKinds.has(kind) && kind === streakKind) {
|
|
127
|
+
streakLines.push({ line: para.line, preview: sentence.slice(0, 24) });
|
|
128
|
+
} else {
|
|
129
|
+
flushStreak();
|
|
130
|
+
streakKind = streakKinds.has(kind) ? kind : null;
|
|
131
|
+
streakLines = streakKind ? [{ line: para.line, preview: sentence.slice(0, 24) }] : [];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (cls.kind === "subjectless" && prevActor && !protagonistNames.has(prevActor)) {
|
|
135
|
+
result.ambiguityHits.push({
|
|
136
|
+
line: para.line,
|
|
137
|
+
scope: prevActorPara === paraIdx ? "same-paragraph" : "next-paragraph",
|
|
138
|
+
previousActor: prevActor,
|
|
139
|
+
previous: prevActorText.slice(0, 40),
|
|
140
|
+
current: sentence.slice(0, 40),
|
|
141
|
+
});
|
|
142
|
+
// 同一个主语只报第一处,避免一串无主语句被重复报出
|
|
143
|
+
prevActor = null;
|
|
144
|
+
}
|
|
145
|
+
if ((cls.kind === "name" || cls.kind === "delayed") && cls.clauseIndex <= maxActorClause) {
|
|
146
|
+
prevActor = cls.actor;
|
|
147
|
+
prevActorText = sentence;
|
|
148
|
+
prevActorPara = paraIdx;
|
|
149
|
+
} else if (cls.kind === "pronoun") {
|
|
150
|
+
prevActor = null;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
// 含对白的段落结束后不把主语带到下一段
|
|
154
|
+
if (hasDialogue) prevActor = null;
|
|
155
|
+
});
|
|
156
|
+
flushStreak();
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// 校验审稿编辑输出的 JSON 报告是否严格具备原文举证且未越权干预纯文笔风格
|
|
2
|
+
export function validateEvidenceReview(
|
|
3
|
+
chapterText,
|
|
4
|
+
reviewPayload,
|
|
5
|
+
customLingConfig
|
|
6
|
+
) {
|
|
7
|
+
const cfg = customLingConfig;
|
|
8
|
+
if (!cfg) {
|
|
9
|
+
throw new Error("linguisticsConfig is required for validateEvidenceReview.");
|
|
10
|
+
}
|
|
11
|
+
const allowedCategories = new Set(cfg.allowedReviewCategories);
|
|
12
|
+
const bannedKeywords = cfg.bannedStyleReviewKeywords;
|
|
13
|
+
const quoteRequiredCategories = new Set(cfg.quoteRequiredCategories || []);
|
|
14
|
+
|
|
15
|
+
const issues = [];
|
|
16
|
+
if (!reviewPayload || !Array.isArray(reviewPayload.items)) {
|
|
17
|
+
return {
|
|
18
|
+
valid: false,
|
|
19
|
+
issues: [{ code: "INVALID_SCHEMA", detail: "Missing items array." }],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const normalizedChapter = chapterText.replace(/\s+/gu, "");
|
|
24
|
+
|
|
25
|
+
reviewPayload.items.forEach((item, index) => {
|
|
26
|
+
// 1. 检查审稿分类是否在允许的客观事实与因果维度内
|
|
27
|
+
if (!allowedCategories.has(item.category)) {
|
|
28
|
+
issues.push({
|
|
29
|
+
index,
|
|
30
|
+
code: "UNAUTHORIZED_REVIEW_CATEGORY",
|
|
31
|
+
category: item.category,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 2. 非 pass 项与读者反应项必须附带可在正文中逐字定位的真实 quote(防审稿幻觉)
|
|
36
|
+
const quoteRequired =
|
|
37
|
+
item.severity === "error" ||
|
|
38
|
+
item.severity === "warning" ||
|
|
39
|
+
quoteRequiredCategories.has(item.category);
|
|
40
|
+
if (quoteRequired) {
|
|
41
|
+
if (!item.quote || typeof item.quote !== "string" || !item.quote.trim()) {
|
|
42
|
+
issues.push({
|
|
43
|
+
index,
|
|
44
|
+
code: "MISSING_EVIDENCE_QUOTE",
|
|
45
|
+
severity: item.severity,
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
const normalizedQuote = item.quote.replace(/\s+/gu, "");
|
|
49
|
+
if (!normalizedChapter.includes(normalizedQuote)) {
|
|
50
|
+
issues.push({
|
|
51
|
+
index,
|
|
52
|
+
code: "HALLUCINATED_QUOTE_NOT_IN_TEXT",
|
|
53
|
+
quote: item.quote.slice(0, 60),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 3. 拦截要求“增加五感/丰富形容词/升级动词”等会污染人类文风的越权评语
|
|
60
|
+
const desc = String(item.description || "");
|
|
61
|
+
for (const banned of bannedKeywords) {
|
|
62
|
+
if (desc.includes(banned)) {
|
|
63
|
+
issues.push({
|
|
64
|
+
index,
|
|
65
|
+
code: "BANNED_STYLE_INTERFERENCE",
|
|
66
|
+
matchedKeyword: banned,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
valid: issues.length === 0,
|
|
74
|
+
checkedCount: reviewPayload.items.length,
|
|
75
|
+
issues,
|
|
76
|
+
};
|
|
77
|
+
}
|