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,175 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { profileText } from "./profiler.mjs";
4
+ import { loadLinguisticsConfig } from "./config-loader.mjs";
5
+
6
+ // 参与参考区间统计的指标(与篇幅关系较小、可在章节之间比较的比率类指标)
7
+ const REFERENCE_METRICS = [
8
+ "sentLenMean",
9
+ "sentLenCV",
10
+ "flowingSentRatio",
11
+ "ultraShortSentRatio",
12
+ "dePer100Han",
13
+ "longModPerClause",
14
+ "mattr50",
15
+ "hapaxRatio",
16
+ "topicAnchorRatio",
17
+ "sentsPerParaMean",
18
+ "paraLenMean",
19
+ "emDashPer1kHan",
20
+ ];
21
+
22
+ // 样本数和单样本篇幅达到这两个数,参考区间才标为可靠
23
+ const MIN_RELIABLE_SAMPLES = 20;
24
+ const MIN_RELIABLE_HAN = 2000;
25
+
26
+ // 线性插值求分位数
27
+ function quantile(sorted, q) {
28
+ if (sorted.length === 0) return null;
29
+ const pos = (sorted.length - 1) * q;
30
+ const lo = Math.floor(pos);
31
+ const hi = Math.ceil(pos);
32
+ const v = sorted[lo] + (sorted[hi] - sorted[lo]) * (pos - lo);
33
+ return Math.round(v * 1000) / 1000;
34
+ }
35
+
36
+ // 递归收集目录或文件列表下的全部 .md / .txt 文本(递归时跳过隐藏目录、node_modules 与下划线开头的备份子目录)
37
+ export function collectTextFiles(inputs) {
38
+ const files = [];
39
+ const walkDir = (dirPath) => {
40
+ for (const entry of fs.readdirSync(dirPath, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true }))) {
41
+ if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
42
+ if (entry.isDirectory() && entry.name.startsWith("_")) continue;
43
+ const full = path.join(dirPath, entry.name);
44
+ if (entry.isDirectory()) {
45
+ walkDir(full);
46
+ } else if (entry.isFile() && /\.(md|txt)$/u.test(entry.name)) {
47
+ files.push(full);
48
+ }
49
+ }
50
+ };
51
+ for (const input of inputs) {
52
+ const resolved = path.resolve(input);
53
+ if (!fs.existsSync(resolved)) continue;
54
+ const stat = fs.statSync(resolved);
55
+ if (stat.isDirectory()) {
56
+ walkDir(resolved);
57
+ } else {
58
+ files.push(resolved);
59
+ }
60
+ }
61
+ return files;
62
+ }
63
+
64
+ // 从一批人类文本计算各指标的 p10 / 中位数 / p90,只输出统计结果,不输出原文
65
+ export function calibrateReference(texts, options = {}) {
66
+ const lingConfig = options.linguisticsConfig || loadLinguisticsConfig();
67
+ const profiles = texts.map((t) => profileText(t, lingConfig).metrics);
68
+ const hanCounts = profiles.map((p) => p.totalHan).sort((a, b) => a - b);
69
+ const metrics = {};
70
+ for (const key of REFERENCE_METRICS) {
71
+ const values = profiles
72
+ .map((p) => p[key])
73
+ .filter((v) => typeof v === "number" && Number.isFinite(v))
74
+ .sort((a, b) => a - b);
75
+ if (values.length === 0) continue;
76
+ metrics[key] = {
77
+ p10: quantile(values, 0.1),
78
+ median: quantile(values, 0.5),
79
+ p90: quantile(values, 0.9),
80
+ min: values[0],
81
+ max: values[values.length - 1],
82
+ };
83
+ }
84
+ const shortSamples = hanCounts.filter((h) => h < MIN_RELIABLE_HAN).length;
85
+ const reliable =
86
+ profiles.length >= MIN_RELIABLE_SAMPLES && shortSamples === 0;
87
+ return {
88
+ kind: "inkbone-human-reference",
89
+ label: options.label || "",
90
+ sampleCount: profiles.length,
91
+ medianSampleHan: quantile(hanCounts, 0.5),
92
+ shortSampleCount: shortSamples,
93
+ reliable,
94
+ reliabilityRule: {
95
+ minSamples: MIN_RELIABLE_SAMPLES,
96
+ minHanPerSample: MIN_RELIABLE_HAN,
97
+ },
98
+ metrics,
99
+ };
100
+ }
101
+
102
+ // 统计纯汉字 n-gram 计数(按标点切成小句,避免跨句拼接)
103
+ function countNgrams(text, n, counts) {
104
+ const clauses = text.split(/[^\p{Script=Han}]+/u);
105
+ let total = 0;
106
+ for (const clause of clauses) {
107
+ const chars = Array.from(clause);
108
+ for (let i = 0; i + n <= chars.length; i += 1) {
109
+ const g = chars.slice(i, i + n).join("");
110
+ counts.set(g, (counts.get(g) || 0) + 1);
111
+ total += 1;
112
+ }
113
+ }
114
+ return total;
115
+ }
116
+
117
+ // 对比 AI 稿与人类文本,找出在 AI 稿里出现率明显偏高的搭配,作为套话词表候选
118
+ export function mineOverusedPhrases(aiTexts, humanTexts, options = {}) {
119
+ const sizes = options.sizes || [3, 4];
120
+ const minAiCount = options.minAiCount ?? 3;
121
+ const minRatio = options.minRatio ?? 5;
122
+ const top = options.top ?? 80;
123
+ const exclude = new Set(options.exclude || []);
124
+ // 故事词表:设定、大纲、人物卡里出现过的 n-gram 视为本书专名,不当套话
125
+ const vocabTexts = options.vocabTexts || [];
126
+ const results = [];
127
+ for (const n of sizes) {
128
+ const aiCounts = new Map();
129
+ const humanCounts = new Map();
130
+ const aiDocFreq = new Map();
131
+ let aiTotal = 0;
132
+ let humanTotal = 0;
133
+ for (const t of aiTexts) {
134
+ const local = new Map();
135
+ aiTotal += countNgrams(t, n, local);
136
+ for (const [g, c] of local) {
137
+ aiCounts.set(g, (aiCounts.get(g) || 0) + c);
138
+ aiDocFreq.set(g, (aiDocFreq.get(g) || 0) + 1);
139
+ }
140
+ }
141
+ for (const t of humanTexts) humanTotal += countNgrams(t, n, humanCounts);
142
+ const vocabCounts = new Map();
143
+ for (const t of vocabTexts) countNgrams(t, n, vocabCounts);
144
+ if (aiTotal === 0 || humanTotal === 0) continue;
145
+ for (const [g, aiCount] of aiCounts) {
146
+ if (aiCount < minAiCount || exclude.has(g) || vocabCounts.has(g)) continue;
147
+ // 只保留在两篇及以上 AI 稿里都出现的搭配,排除单章专名
148
+ if (aiTexts.length > 1 && (aiDocFreq.get(g) || 0) < 2) continue;
149
+ const humanCount = humanCounts.get(g) || 0;
150
+ // 加 0.5 平滑后比较每万字出现率
151
+ const aiRate = ((aiCount + 0.5) / aiTotal) * 1e4;
152
+ const humanRate = ((humanCount + 0.5) / humanTotal) * 1e4;
153
+ const ratio = aiRate / humanRate;
154
+ if (ratio < minRatio) continue;
155
+ results.push({
156
+ phrase: g,
157
+ n,
158
+ aiCount,
159
+ aiDocs: aiDocFreq.get(g) || 0,
160
+ humanCount,
161
+ aiPer10k: Math.round(aiRate * 100) / 100,
162
+ humanPer10k: Math.round(humanRate * 100) / 100,
163
+ ratio: Math.round(ratio * 10) / 10,
164
+ });
165
+ }
166
+ }
167
+ results.sort((a, b) => b.ratio * Math.log(b.aiCount + 1) - a.ratio * Math.log(a.aiCount + 1));
168
+ return {
169
+ kind: "inkbone-phrase-candidates",
170
+ note: "candidates only; review each phrase in context before adding it to a blocklist",
171
+ aiDocs: aiTexts.length,
172
+ humanDocs: humanTexts.length,
173
+ candidates: results.slice(0, top),
174
+ };
175
+ }
@@ -0,0 +1,233 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import {
5
+ compileGenresConfig,
6
+ compileLinguisticsConfig,
7
+ compileProjectRules,
8
+ compileSeverityConfig,
9
+ compileTraditionalConfig,
10
+ resolveGenreFromConfig,
11
+ resolvePresetFromConfig,
12
+ } from "./core/config-compiler.mjs";
13
+
14
+ export { compileProjectRules };
15
+
16
+ // 解析内置配置文件所在目录路径
17
+ const currentFile = fileURLToPath(import.meta.url);
18
+ const srcDir = path.dirname(currentFile);
19
+ const rootDir = path.resolve(srcDir, "..");
20
+ const defaultLingPath = path.resolve(rootDir, "configs/zh-linguistics.json");
21
+ const defaultPresetsPath = path.resolve(rootDir, "configs/presets.json");
22
+ const defaultGenresPath = path.resolve(rootDir, "configs/genres.json");
23
+ const defaultMessagesPath = path.resolve(rootDir, "configs/messages.json");
24
+ const defaultTraditionalPath = path.resolve(rootDir, "configs/zh-traditional.json");
25
+ const defaultPlatformsPath = path.resolve(rootDir, "configs/platforms.json");
26
+
27
+ let cachedLinguistics = null;
28
+ let cachedPresets = null;
29
+ let cachedGenres = null;
30
+ let cachedSeverity = null;
31
+ let cachedMessages = null;
32
+ let cachedTraditional = null;
33
+ let cachedPlatforms = null;
34
+
35
+ // 加载并缓存中文计算语言学配置与预编译正则表达式
36
+ export function loadLinguisticsConfig(customPath = null) {
37
+ if (!customPath && cachedLinguistics) {
38
+ return cachedLinguistics;
39
+ }
40
+ const targetPath = customPath ? path.resolve(customPath) : defaultLingPath;
41
+ const raw = JSON.parse(fs.readFileSync(targetPath, "utf8"));
42
+ const compiled = compileLinguisticsConfig(raw);
43
+ if (!customPath) {
44
+ cachedLinguistics = compiled;
45
+ }
46
+ return compiled;
47
+ }
48
+
49
+ // 加载并缓存多题材语域防火墙与通用减法规则配置
50
+ export function loadGenresConfig(customPath = null) {
51
+ if (!customPath && cachedGenres) {
52
+ return cachedGenres;
53
+ }
54
+ const targetPath = customPath ? path.resolve(customPath) : defaultGenresPath;
55
+ const raw = JSON.parse(fs.readFileSync(targetPath, "utf8"));
56
+ const compiled = compileGenresConfig(raw);
57
+ if (!customPath) {
58
+ cachedGenres = compiled;
59
+ }
60
+ return compiled;
61
+ }
62
+
63
+ // 根据题材标识解析对应的语域防火墙数据包
64
+ export function resolveGenre(genreName, customPath = null) {
65
+ return resolveGenreFromConfig(loadGenresConfig(customPath), genreName);
66
+ }
67
+
68
+ // 加载并缓存大师声口预设门禁参数配置
69
+ export function loadPresetsConfig(customPath = null) {
70
+ if (!customPath && cachedPresets) {
71
+ return cachedPresets;
72
+ }
73
+ const targetPath = customPath ? path.resolve(customPath) : defaultPresetsPath;
74
+ const parsed = JSON.parse(fs.readFileSync(targetPath, "utf8"));
75
+ if (!customPath) {
76
+ cachedPresets = parsed;
77
+ }
78
+ return parsed;
79
+ }
80
+
81
+ // 加载违规码分级配置,返回 code -> level 映射
82
+ export function loadSeverityConfig(customPath = null) {
83
+ if (!customPath && cachedSeverity) {
84
+ return cachedSeverity;
85
+ }
86
+ const targetPath = customPath
87
+ ? path.resolve(customPath)
88
+ : path.resolve(rootDir, "configs/severity.json");
89
+ const raw = JSON.parse(fs.readFileSync(targetPath, "utf8"));
90
+ const compiled = compileSeverityConfig(raw);
91
+ if (!customPath) {
92
+ cachedSeverity = compiled;
93
+ }
94
+ return compiled;
95
+ }
96
+
97
+ // 加载中英双语展示文案与精准改稿提示词模板配置
98
+ export function loadMessagesConfig(customPath = null) {
99
+ if (!customPath && cachedMessages) {
100
+ return cachedMessages;
101
+ }
102
+ const targetPath = customPath ? path.resolve(customPath) : defaultMessagesPath;
103
+ const parsed = JSON.parse(fs.readFileSync(targetPath, "utf8"));
104
+ if (!customPath) {
105
+ cachedMessages = parsed;
106
+ }
107
+ return parsed;
108
+ }
109
+
110
+ // 加载并编译繁体中文 / 港台网文规则层配置
111
+ export function loadTraditionalConfig(customPath = null) {
112
+ if (!customPath && cachedTraditional) {
113
+ return cachedTraditional;
114
+ }
115
+ const targetPath = customPath ? path.resolve(customPath) : defaultTraditionalPath;
116
+ const raw = JSON.parse(fs.readFileSync(targetPath, "utf8"));
117
+ const compiled = compileTraditionalConfig(raw);
118
+ if (!customPath) {
119
+ cachedTraditional = compiled;
120
+ }
121
+ return compiled;
122
+ }
123
+
124
+ // 加载网文平台投稿导出清洗预设配置
125
+ export function loadPlatformsConfig(customPath = null) {
126
+ if (!customPath && cachedPlatforms) {
127
+ return cachedPlatforms;
128
+ }
129
+ const targetPath = customPath ? path.resolve(customPath) : defaultPlatformsPath;
130
+ const parsed = JSON.parse(fs.readFileSync(targetPath, "utf8"));
131
+ if (!customPath) {
132
+ cachedPlatforms = parsed;
133
+ }
134
+ return parsed;
135
+ }
136
+
137
+ // 根据预设名称解析对应的阈值配置对象
138
+ export function resolvePreset(presetName, customPath = null) {
139
+ return resolvePresetFromConfig(loadPresetsConfig(customPath), presetName);
140
+ }
141
+
142
+ const PROJECT_CONFIG_NAME = "novel.json";
143
+ const PROJECT_SEARCH_DEPTH = 6;
144
+
145
+ // 从章节所在目录逐级向上查找书目录里的 novel.json
146
+ export function findProjectConfig(startDir) {
147
+ let curDir = path.resolve(startDir || process.cwd());
148
+ for (let depth = 0; depth < PROJECT_SEARCH_DEPTH; depth += 1) {
149
+ const candidate = path.join(curDir, PROJECT_CONFIG_NAME);
150
+ if (fs.existsSync(candidate)) return candidate;
151
+ const parent = path.dirname(curDir);
152
+ if (parent === curDir) break;
153
+ curDir = parent;
154
+ }
155
+ return null;
156
+ }
157
+
158
+ const DEFAULT_WHITELIST_FILE = ".inkbone-whitelist";
159
+
160
+ // 读取纯字面量书级白名单文件(忽略空行与井号注释,不支持正则与跨目录继承)
161
+ export function loadWhitelistFile(filePath) {
162
+ const absPath = path.resolve(filePath);
163
+ if (!fs.existsSync(absPath)) return [];
164
+ return fs
165
+ .readFileSync(absPath, "utf8")
166
+ .split(/\r?\n/u)
167
+ .map((line) => line.trim())
168
+ .filter((line) => line.length > 0 && !line.startsWith("#"));
169
+ }
170
+
171
+ // 加载书目录的 novel.json(或直接给出的规则文件),合并内联 projectRules、rulesFile 与书级白名单
172
+ export function loadProjectConfig(configPath) {
173
+ const absPath = path.resolve(configPath);
174
+ const raw = JSON.parse(fs.readFileSync(absPath, "utf8"));
175
+ const baseDir = path.dirname(absPath);
176
+ const isBareRulesFile =
177
+ !raw.projectRules &&
178
+ !raw.rulesFile &&
179
+ !raw.genre &&
180
+ !raw.projectTitle &&
181
+ !raw.whitelistFile;
182
+ const layers = [];
183
+ if (isBareRulesFile) layers.push(raw);
184
+ if (raw.rulesFile) {
185
+ layers.push(
186
+ JSON.parse(fs.readFileSync(path.resolve(baseDir, raw.rulesFile), "utf8"))
187
+ );
188
+ }
189
+ if (raw.projectRules) layers.push(raw.projectRules);
190
+
191
+ const merged = {
192
+ clicheRules: [],
193
+ fillerRules: [],
194
+ registerRules: [],
195
+ symmetricSkeletons: [],
196
+ rhetoricalRules: [],
197
+ disabledRuleIds: [],
198
+ whitelistLiterals: [],
199
+ };
200
+ for (const layer of layers) {
201
+ for (const key of Object.keys(merged)) {
202
+ merged[key].push(...(layer[key] || []));
203
+ }
204
+ }
205
+
206
+ // 读取书级字面量白名单(显式 whitelistFile 或同目录下的 .inkbone-whitelist)
207
+ const explicitWhitelist = raw.whitelistFile
208
+ ? path.resolve(baseDir, raw.whitelistFile)
209
+ : null;
210
+ const defaultWhitelist = path.join(baseDir, DEFAULT_WHITELIST_FILE);
211
+ if (explicitWhitelist) {
212
+ merged.whitelistLiterals.push(...loadWhitelistFile(explicitWhitelist));
213
+ } else if (fs.existsSync(defaultWhitelist)) {
214
+ merged.whitelistLiterals.push(...loadWhitelistFile(defaultWhitelist));
215
+ }
216
+
217
+ return {
218
+ path: absPath,
219
+ projectTitle: raw.projectTitle || null,
220
+ genre: raw.genre || null,
221
+ preset: raw.preset || null,
222
+ variant: raw.variant || null,
223
+ customGates:
224
+ raw.customGates && typeof raw.customGates === "object" && !Array.isArray(raw.customGates)
225
+ ? raw.customGates
226
+ : null,
227
+ ledgerFile: raw.ledgerFile ? path.resolve(baseDir, raw.ledgerFile) : null,
228
+ whitelistFile:
229
+ explicitWhitelist ||
230
+ (fs.existsSync(defaultWhitelist) ? defaultWhitelist : null),
231
+ rules: compileProjectRules(merged),
232
+ };
233
+ }
@@ -0,0 +1,5 @@
1
+ // 主语连续性检查(委托给零文件系统依赖的 core 模块)
2
+ export {
3
+ collectCharacterNames,
4
+ scanSubjectContinuity,
5
+ } from "./core/continuity.mjs";