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.
Files changed (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +318 -0
  3. package/README.md +333 -2
  4. package/bin/inkbone.mjs +941 -0
  5. package/configs/genres.json +570 -0
  6. package/configs/messages.json +302 -0
  7. package/configs/platforms.json +62 -0
  8. package/configs/presets.json +265 -0
  9. package/configs/severity.json +52 -0
  10. package/configs/zh-linguistics.json +986 -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 +61 -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 +60 -0
  18. package/prompts/03-targeted-rewriter.md +39 -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 +98 -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 +21 -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 +334 -0
  37. package/skills/inkbone/SKILL.md +155 -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 +941 -0
  42. package/skills/inkbone/configs/genres.json +570 -0
  43. package/skills/inkbone/configs/messages.json +302 -0
  44. package/skills/inkbone/configs/platforms.json +62 -0
  45. package/skills/inkbone/configs/presets.json +265 -0
  46. package/skills/inkbone/configs/severity.json +52 -0
  47. package/skills/inkbone/configs/zh-linguistics.json +986 -0
  48. package/skills/inkbone/configs/zh-traditional.json +97 -0
  49. package/skills/inkbone/package.json +63 -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 +60 -0
  53. package/skills/inkbone/prompts/03-targeted-rewriter.md +39 -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 +98 -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 +21 -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/auditor.mjs +24 -0
  71. package/skills/inkbone/src/benchmark-runner.mjs +71 -0
  72. package/skills/inkbone/src/boundary-compiler.mjs +54 -0
  73. package/skills/inkbone/src/browser-doctor.mjs +30 -0
  74. package/skills/inkbone/src/calibrator.mjs +175 -0
  75. package/skills/inkbone/src/config-loader.mjs +233 -0
  76. package/skills/inkbone/src/continuity.mjs +5 -0
  77. package/skills/inkbone/src/core/auditor.mjs +914 -0
  78. package/skills/inkbone/src/core/boundary-compiler.mjs +423 -0
  79. package/skills/inkbone/src/core/browser-doctor.mjs +318 -0
  80. package/skills/inkbone/src/core/config-compiler.mjs +434 -0
  81. package/skills/inkbone/src/core/continuity.mjs +158 -0
  82. package/skills/inkbone/src/core/evidence-validator.mjs +77 -0
  83. package/skills/inkbone/src/core/exporter.mjs +128 -0
  84. package/skills/inkbone/src/core/formatter.mjs +241 -0
  85. package/skills/inkbone/src/core/ledger-manager.mjs +576 -0
  86. package/skills/inkbone/src/core/normalizer.mjs +517 -0
  87. package/skills/inkbone/src/core/profiler.mjs +686 -0
  88. package/skills/inkbone/src/core/rule-engine.mjs +1536 -0
  89. package/skills/inkbone/src/core/style-profiler.mjs +229 -0
  90. package/skills/inkbone/src/detector.mjs +270 -0
  91. package/skills/inkbone/src/doctor.mjs +428 -0
  92. package/skills/inkbone/src/evaluation.mjs +311 -0
  93. package/skills/inkbone/src/evidence-validator.mjs +15 -0
  94. package/skills/inkbone/src/exporter.mjs +106 -0
  95. package/skills/inkbone/src/formatter.mjs +34 -0
  96. package/skills/inkbone/src/importer.mjs +230 -0
  97. package/skills/inkbone/src/index.mjs +116 -0
  98. package/skills/inkbone/src/ledger-manager.mjs +15 -0
  99. package/skills/inkbone/src/mcp-server.mjs +861 -0
  100. package/skills/inkbone/src/normalizer.mjs +73 -0
  101. package/skills/inkbone/src/profiler.mjs +17 -0
  102. package/skills/inkbone/src/rule-engine.mjs +73 -0
  103. package/skills/inkbone/src/rule-stats.mjs +142 -0
  104. package/skills/inkbone/src/style-profiler.mjs +25 -0
  105. package/src/auditor.mjs +24 -0
  106. package/src/benchmark-runner.mjs +71 -0
  107. package/src/boundary-compiler.mjs +54 -0
  108. package/src/browser-doctor.mjs +30 -0
  109. package/src/calibrator.mjs +175 -0
  110. package/src/config-loader.mjs +233 -0
  111. package/src/continuity.mjs +5 -0
  112. package/src/core/auditor.mjs +914 -0
  113. package/src/core/boundary-compiler.mjs +423 -0
  114. package/src/core/browser-doctor.mjs +318 -0
  115. package/src/core/config-compiler.mjs +434 -0
  116. package/src/core/continuity.mjs +158 -0
  117. package/src/core/evidence-validator.mjs +77 -0
  118. package/src/core/exporter.mjs +128 -0
  119. package/src/core/formatter.mjs +241 -0
  120. package/src/core/ledger-manager.mjs +576 -0
  121. package/src/core/normalizer.mjs +517 -0
  122. package/src/core/profiler.mjs +686 -0
  123. package/src/core/rule-engine.mjs +1536 -0
  124. package/src/core/style-profiler.mjs +229 -0
  125. package/src/detector.mjs +270 -0
  126. package/src/doctor.mjs +428 -0
  127. package/src/evaluation.mjs +311 -0
  128. package/src/evidence-validator.mjs +15 -0
  129. package/src/exporter.mjs +106 -0
  130. package/src/formatter.mjs +34 -0
  131. package/src/importer.mjs +230 -0
  132. package/src/index.mjs +116 -0
  133. package/src/ledger-manager.mjs +15 -0
  134. package/src/mcp-server.mjs +861 -0
  135. package/src/normalizer.mjs +73 -0
  136. package/src/profiler.mjs +17 -0
  137. package/src/rule-engine.mjs +73 -0
  138. package/src/rule-stats.mjs +142 -0
  139. package/src/style-profiler.mjs +25 -0
@@ -0,0 +1,318 @@
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
+ strict: Boolean(options.strict),
186
+ variant: options.variant || "auto",
187
+ linguisticsConfig: lingConfig,
188
+ genresConfig,
189
+ presetsConfig,
190
+ severityConfig,
191
+ traditionalConfig: options.traditionalConfig || null,
192
+ projectRules: options.projectRules || null,
193
+ });
194
+
195
+ const getCount = (code) => {
196
+ const v = audit.violations.find((item) => item.code === code);
197
+ return v ? v.count || (v.hits ? v.hits.length : 1) : 0;
198
+ };
199
+ const echoV = audit.violations.find((v) => v.code === "PREVIOUS_ENDING_ECHO");
200
+ const echoRatio = echoV ? echoV.actual : 0;
201
+
202
+ const regCount = getCount("REGISTER_COLLISION");
203
+ const filCount = getCount("NARRATIVE_FILLER");
204
+ const cliCount = getCount("FORBIDDEN_AI_CLICHE");
205
+ const subjCount = getCount("SUBJECT_AMBIGUITY");
206
+
207
+ totals.totalHan += audit.metrics.totalHan;
208
+ totals.hardErrors += audit.summary.error;
209
+ totals.totalWarnings += audit.summary.warning;
210
+ totals.registerCollisions += regCount;
211
+ totals.narrativeFillers += filCount;
212
+ totals.aiCliches += cliCount;
213
+ totals.subjectAmbiguities += subjCount;
214
+ if (echoV) totals.echoWarnings += 1;
215
+
216
+ // 累加规则标签出现次数用于全书高频问题榜
217
+ for (const target of audit.surgeryTargets || []) {
218
+ for (const issue of target.issues || []) {
219
+ const rec = ruleCounter.get(issue.tag) || {
220
+ tag: issue.tag,
221
+ count: 0,
222
+ chapters: new Set(),
223
+ sample: issue.detail || "",
224
+ level: issue.level || "advisory",
225
+ };
226
+ rec.count += 1;
227
+ rec.chapters.add(entry.name);
228
+ if (issue.level === "blocking") rec.level = "blocking";
229
+ ruleCounter.set(issue.tag, rec);
230
+ }
231
+ }
232
+
233
+ const dialogueRatio = computeChapterDialogueRatio(
234
+ entry.text,
235
+ lingConfig,
236
+ audit.metrics.totalHan
237
+ );
238
+
239
+ chapters.push({
240
+ name: entry.name,
241
+ chapterNumber: entry.chapterNumber,
242
+ title: entry.title,
243
+ pass: audit.pass,
244
+ scriptVariant: audit.scriptVariant || "zh-hans",
245
+ totalHan: audit.metrics.totalHan,
246
+ dialogueRatio,
247
+ echoRatio,
248
+ summary: audit.summary,
249
+ counts: {
250
+ registerCollisions: regCount,
251
+ narrativeFillers: filCount,
252
+ aiCliches: cliCount,
253
+ subjectAmbiguities: subjCount,
254
+ },
255
+ surgeryTargetCount: audit.surgeryTargets.length,
256
+ surgeryTargets: audit.surgeryTargets,
257
+ violations: audit.violations.filter((v) => v.severity !== "info"),
258
+ });
259
+
260
+ trend.push({
261
+ name: entry.name,
262
+ chapterNumber: entry.chapterNumber ?? idx + 1,
263
+ totalHan: audit.metrics.totalHan,
264
+ dialogueRatio,
265
+ errors: audit.summary.error,
266
+ warnings: audit.summary.warning,
267
+ echoRatio,
268
+ });
269
+
270
+ ledgerChapters.push({
271
+ chapterNumber: entry.chapterNumber ?? idx + 1,
272
+ title: entry.title,
273
+ hanCount: countHan(entry.text, hanRegex),
274
+ sourceFile: entry.name,
275
+ coreSummary: "",
276
+ requiredAnchors: [],
277
+ futureForbiddenTerms: [],
278
+ });
279
+ });
280
+
281
+ const topRules = Array.from(ruleCounter.values())
282
+ .map((r) => ({
283
+ tag: r.tag,
284
+ count: r.count,
285
+ chapterCount: r.chapters.size,
286
+ level: r.level,
287
+ sample: r.sample,
288
+ }))
289
+ .sort((a, b) => b.count - a.count || b.chapterCount - a.chapterCount)
290
+ .slice(0, 10);
291
+
292
+ const suggestedLedger = {
293
+ projectTitle: options.projectTitle || "",
294
+ protagonist: autoNames[0] ? { name: autoNames[0] } : "",
295
+ characterNames: autoNames,
296
+ immutableWorldRules: [],
297
+ deprecatedTerms: [],
298
+ knowledgeLedger: [],
299
+ characterSnapshots: {},
300
+ foreshadowing: [],
301
+ chapters: ledgerChapters,
302
+ };
303
+
304
+ return {
305
+ pass: totals.hardErrors === 0,
306
+ genre: {
307
+ id: genrePack.id,
308
+ title: genrePack.title,
309
+ source: options.genre ? "explicit" : inferred.autoDetected ? "inferred" : "default",
310
+ },
311
+ totals,
312
+ topRules,
313
+ trend,
314
+ candidateCharacters,
315
+ suggestedLedger,
316
+ chapters,
317
+ };
318
+ }