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,320 @@
1
+ // 纯内存整书多章体检引擎(Browser Doctor:零文件系统依赖,供浏览器静态试跑台与内存批量分析共用)
2
+ import { auditChapterText } from "./auditor.mjs";
3
+ import { resolveGenreFromConfig } from "./config-compiler.mjs";
4
+ import { countHan } from "./profiler.mjs";
5
+ import { parseChineseOrArabicNumber, stripSpokenDialogue } from "./rule-engine.mjs";
6
+ import { extractCandidateCharacters } from "./ledger-manager.mjs";
7
+
8
+ // 纯内存解析单章的章节号与标题(复用与 importer.mjs 一致的中文/阿拉伯章号正则)
9
+ export function parseChapterMetaFromEntry(fileName, rawText, lingConfig) {
10
+ const cn = lingConfig?.chineseNumerals || {};
11
+ const headingRe = cn.chapterHeadingParseRegex ? new RegExp(cn.chapterHeadingParseRegex) : null;
12
+ const fileRe = cn.chapterFileParseRegex ? new RegExp(cn.chapterFileParseRegex) : null;
13
+
14
+ const lines = String(rawText || "")
15
+ .split(/\r?\n/u)
16
+ .map((l) => l.trim())
17
+ .filter(Boolean)
18
+ .slice(0, 8);
19
+
20
+ if (headingRe) {
21
+ for (const line of lines) {
22
+ const m = headingRe.exec(line);
23
+ if (m) {
24
+ const num = parseChineseOrArabicNumber(m[1], cn);
25
+ if (num !== null) {
26
+ return {
27
+ chapterNumber: num,
28
+ title: (m[2] || "").replace(/^[_:\-\s\u2014]+/, "").trim(),
29
+ };
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ if (fileRe && fileName) {
36
+ const m = fileRe.exec(fileName);
37
+ if (m) {
38
+ const num = parseChineseOrArabicNumber(m[1], cn);
39
+ if (num !== null) {
40
+ return {
41
+ chapterNumber: num,
42
+ title: (m[2] || "").replace(/^[_:\-\s\u2014]+/, "").trim(),
43
+ };
44
+ }
45
+ }
46
+ }
47
+
48
+ if (fileName) {
49
+ const fallback = String(fileName).match(/(\d{1,4})/u);
50
+ if (fallback) {
51
+ return { chapterNumber: Number(fallback[1]), title: "" };
52
+ }
53
+ }
54
+
55
+ return { chapterNumber: null, title: "" };
56
+ }
57
+
58
+ // 纯内存题材信号推断(复用 genresConfig.domainSignals)
59
+ export function inferGenreFromEntries(texts, genresConfig) {
60
+ const combined = (texts || []).join("\n");
61
+ let bestId = genresConfig.defaultGenre;
62
+ let bestScore = 0;
63
+
64
+ for (const [id, pack] of Object.entries(genresConfig.genres || {})) {
65
+ const signals = pack.domainSignals || [];
66
+ if (signals.length === 0) continue;
67
+ let distinctHits = 0;
68
+ let totalHits = 0;
69
+ for (const sig of signals) {
70
+ const count = combined.split(sig).length - 1;
71
+ if (count > 0) {
72
+ distinctHits += 1;
73
+ totalHits += count;
74
+ }
75
+ }
76
+ if (distinctHits >= 2) {
77
+ const score = distinctHits * 10 + Math.min(totalHits, 60);
78
+ if (score > bestScore) {
79
+ bestScore = score;
80
+ bestId = id;
81
+ }
82
+ }
83
+ }
84
+ return {
85
+ genreId: bestId,
86
+ autoDetected: bestScore > 0,
87
+ };
88
+ }
89
+
90
+ // 计算单章对白字数占比(供走势图展示)
91
+ function computeChapterDialogueRatio(text, lingConfig, totalHan) {
92
+ if (!totalHan || totalHan <= 0) return 0;
93
+ let spoken = 0;
94
+ for (const line of String(text || "").split(/\r?\n/u)) {
95
+ const t = line.trim();
96
+ if (!t) continue;
97
+ spoken += stripSpokenDialogue(t, lingConfig, " ").spokenChars || 0;
98
+ }
99
+ return Math.round(Math.min(1, spoken / totalHan) * 1000) / 1000;
100
+ }
101
+
102
+ // 对内存中的多章数组执行全书体检、跨章回声检测、高频规则排行与自动台账骨架生成
103
+ export function diagnoseChapterEntries(entries, options = {}) {
104
+ const lingConfig = options.linguisticsConfig;
105
+ const genresConfig = options.genresConfig;
106
+ const presetsConfig = options.presetsConfig;
107
+ const severityConfig = options.severityConfig;
108
+ if (!lingConfig || !genresConfig || !presetsConfig || !severityConfig) {
109
+ throw new Error(
110
+ "linguisticsConfig, genresConfig, presetsConfig, and severityConfig are required."
111
+ );
112
+ }
113
+ const rawList = Array.isArray(entries) ? entries : [];
114
+ if (rawList.length === 0) {
115
+ throw new Error("At least one chapter entry is required for diagnoseChapterEntries.");
116
+ }
117
+
118
+ // 1. 解析章号并按自然章号顺序排序
119
+ const enriched = rawList.map((entry, idx) => {
120
+ const meta = parseChapterMetaFromEntry(entry.name, entry.text, lingConfig);
121
+ return {
122
+ idx,
123
+ name: entry.name || `chapter-${idx + 1}.md`,
124
+ text: String(entry.text || ""),
125
+ chapterNumber: meta.chapterNumber,
126
+ title: meta.title,
127
+ };
128
+ });
129
+ enriched.sort((a, b) => {
130
+ const na = a.chapterNumber ?? Number.MAX_SAFE_INTEGER;
131
+ const nb = b.chapterNumber ?? Number.MAX_SAFE_INTEGER;
132
+ return na - nb || a.idx - b.idx;
133
+ });
134
+
135
+ // 2. 确定题材包与自动挖掘高频角色(未提供 ledger 时用于直接激活主语歧义检查并输出台账骨架)
136
+ const texts = enriched.map((e) => e.text);
137
+ const inferred = options.genre
138
+ ? { genreId: options.genre, autoDetected: false }
139
+ : inferGenreFromEntries(texts.slice(0, 6), genresConfig);
140
+ const genrePack = resolveGenreFromConfig(genresConfig, inferred.genreId);
141
+
142
+ const candidateCharacters = extractCandidateCharacters(texts, lingConfig);
143
+ const autoNames = candidateCharacters.map((c) => c.name);
144
+ const effectiveCharacterNames = Array.from(
145
+ new Set([...(options.characterNames || []), ...(options.ledger?.characterNames || []), ...autoNames])
146
+ );
147
+
148
+ // 3. 逐章审计并统计跨章回声、高频命中规则 Top 10 与走势数据
149
+ const ruleCounter = new Map();
150
+ const totals = {
151
+ chaptersScanned: enriched.length,
152
+ totalHan: 0,
153
+ hardErrors: 0,
154
+ totalWarnings: 0,
155
+ registerCollisions: 0,
156
+ narrativeFillers: 0,
157
+ aiCliches: 0,
158
+ subjectAmbiguities: 0,
159
+ echoWarnings: 0,
160
+ };
161
+
162
+ const hanRegex = lingConfig.compiledRegex.hanCharGlobal;
163
+ const chapters = [];
164
+ const trend = [];
165
+ const ledgerChapters = [];
166
+
167
+ enriched.forEach((entry, idx) => {
168
+ const prev = idx > 0 ? enriched[idx - 1] : null;
169
+ const isAdjacent =
170
+ prev &&
171
+ ((entry.chapterNumber !== null &&
172
+ prev.chapterNumber !== null &&
173
+ entry.chapterNumber === prev.chapterNumber + 1) ||
174
+ (entry.chapterNumber === null && prev.chapterNumber === null));
175
+
176
+ const audit = auditChapterText(entry.text, {
177
+ genre: genrePack.id,
178
+ presetName: options.presetName || genrePack.defaultPreset,
179
+ customGates: options.customGates || null,
180
+ ledger: options.ledger || null,
181
+ chapterNumber: entry.chapterNumber,
182
+ characterNames: effectiveCharacterNames,
183
+ previousChapterText: isAdjacent ? prev.text : "",
184
+ skipLengthGate: Boolean(options.skipLengthGate),
185
+ aigcGuard: Boolean(options.aigcGuard),
186
+ aigcThreshold: options.aigcThreshold,
187
+ strict: Boolean(options.strict),
188
+ variant: options.variant || "auto",
189
+ linguisticsConfig: lingConfig,
190
+ genresConfig,
191
+ presetsConfig,
192
+ severityConfig,
193
+ traditionalConfig: options.traditionalConfig || null,
194
+ projectRules: options.projectRules || null,
195
+ });
196
+
197
+ const getCount = (code) => {
198
+ const v = audit.violations.find((item) => item.code === code);
199
+ return v ? v.count || (v.hits ? v.hits.length : 1) : 0;
200
+ };
201
+ const echoV = audit.violations.find((v) => v.code === "PREVIOUS_ENDING_ECHO");
202
+ const echoRatio = echoV ? echoV.actual : 0;
203
+
204
+ const regCount = getCount("REGISTER_COLLISION");
205
+ const filCount = getCount("NARRATIVE_FILLER");
206
+ const cliCount = getCount("FORBIDDEN_AI_CLICHE");
207
+ const subjCount = getCount("SUBJECT_AMBIGUITY");
208
+
209
+ totals.totalHan += audit.metrics.totalHan;
210
+ totals.hardErrors += audit.summary.error;
211
+ totals.totalWarnings += audit.summary.warning;
212
+ totals.registerCollisions += regCount;
213
+ totals.narrativeFillers += filCount;
214
+ totals.aiCliches += cliCount;
215
+ totals.subjectAmbiguities += subjCount;
216
+ if (echoV) totals.echoWarnings += 1;
217
+
218
+ // 累加规则标签出现次数用于全书高频问题榜
219
+ for (const target of audit.surgeryTargets || []) {
220
+ for (const issue of target.issues || []) {
221
+ const rec = ruleCounter.get(issue.tag) || {
222
+ tag: issue.tag,
223
+ count: 0,
224
+ chapters: new Set(),
225
+ sample: issue.detail || "",
226
+ level: issue.level || "advisory",
227
+ };
228
+ rec.count += 1;
229
+ rec.chapters.add(entry.name);
230
+ if (issue.level === "blocking") rec.level = "blocking";
231
+ ruleCounter.set(issue.tag, rec);
232
+ }
233
+ }
234
+
235
+ const dialogueRatio = computeChapterDialogueRatio(
236
+ entry.text,
237
+ lingConfig,
238
+ audit.metrics.totalHan
239
+ );
240
+
241
+ chapters.push({
242
+ name: entry.name,
243
+ chapterNumber: entry.chapterNumber,
244
+ title: entry.title,
245
+ pass: audit.pass,
246
+ scriptVariant: audit.scriptVariant || "zh-hans",
247
+ totalHan: audit.metrics.totalHan,
248
+ dialogueRatio,
249
+ echoRatio,
250
+ summary: audit.summary,
251
+ counts: {
252
+ registerCollisions: regCount,
253
+ narrativeFillers: filCount,
254
+ aiCliches: cliCount,
255
+ subjectAmbiguities: subjCount,
256
+ },
257
+ surgeryTargetCount: audit.surgeryTargets.length,
258
+ surgeryTargets: audit.surgeryTargets,
259
+ violations: audit.violations.filter((v) => v.severity !== "info"),
260
+ });
261
+
262
+ trend.push({
263
+ name: entry.name,
264
+ chapterNumber: entry.chapterNumber ?? idx + 1,
265
+ totalHan: audit.metrics.totalHan,
266
+ dialogueRatio,
267
+ errors: audit.summary.error,
268
+ warnings: audit.summary.warning,
269
+ echoRatio,
270
+ });
271
+
272
+ ledgerChapters.push({
273
+ chapterNumber: entry.chapterNumber ?? idx + 1,
274
+ title: entry.title,
275
+ hanCount: countHan(entry.text, hanRegex),
276
+ sourceFile: entry.name,
277
+ coreSummary: "",
278
+ requiredAnchors: [],
279
+ futureForbiddenTerms: [],
280
+ });
281
+ });
282
+
283
+ const topRules = Array.from(ruleCounter.values())
284
+ .map((r) => ({
285
+ tag: r.tag,
286
+ count: r.count,
287
+ chapterCount: r.chapters.size,
288
+ level: r.level,
289
+ sample: r.sample,
290
+ }))
291
+ .sort((a, b) => b.count - a.count || b.chapterCount - a.chapterCount)
292
+ .slice(0, 10);
293
+
294
+ const suggestedLedger = {
295
+ projectTitle: options.projectTitle || "",
296
+ protagonist: autoNames[0] ? { name: autoNames[0] } : "",
297
+ characterNames: autoNames,
298
+ immutableWorldRules: [],
299
+ deprecatedTerms: [],
300
+ knowledgeLedger: [],
301
+ characterSnapshots: {},
302
+ foreshadowing: [],
303
+ chapters: ledgerChapters,
304
+ };
305
+
306
+ return {
307
+ pass: totals.hardErrors === 0,
308
+ genre: {
309
+ id: genrePack.id,
310
+ title: genrePack.title,
311
+ source: options.genre ? "explicit" : inferred.autoDetected ? "inferred" : "default",
312
+ },
313
+ totals,
314
+ topRules,
315
+ trend,
316
+ candidateCharacters,
317
+ suggestedLedger,
318
+ chapters,
319
+ };
320
+ }