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.
- package/LICENSE +21 -0
- package/README.en.md +380 -0
- package/README.md +384 -2
- package/bin/inkbone.mjs +1049 -0
- package/configs/genres.json +591 -0
- package/configs/messages.json +336 -0
- package/configs/platforms.json +66 -0
- package/configs/presets.json +265 -0
- package/configs/severity.json +59 -0
- package/configs/zh-linguistics.json +1040 -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 +62 -4
- package/prompts/00-style-architect.md +42 -0
- package/prompts/01-beat-planner.md +54 -0
- package/prompts/02-paratactic-renderer.md +63 -0
- package/prompts/03-targeted-rewriter.md +44 -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 +132 -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 +22 -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 +385 -0
- package/skills/inkbone/SKILL.md +162 -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 +1049 -0
- package/skills/inkbone/configs/genres.json +591 -0
- package/skills/inkbone/configs/messages.json +336 -0
- package/skills/inkbone/configs/platforms.json +66 -0
- package/skills/inkbone/configs/presets.json +265 -0
- package/skills/inkbone/configs/severity.json +59 -0
- package/skills/inkbone/configs/zh-linguistics.json +1040 -0
- package/skills/inkbone/configs/zh-traditional.json +97 -0
- package/skills/inkbone/package.json +64 -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 +63 -0
- package/skills/inkbone/prompts/03-targeted-rewriter.md +44 -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 +132 -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 +22 -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/aigc-guard.mjs +83 -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 +60 -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/aigc-guard.mjs +387 -0
- package/skills/inkbone/src/core/auditor.mjs +1074 -0
- package/skills/inkbone/src/core/boundary-compiler.mjs +526 -0
- package/skills/inkbone/src/core/browser-doctor.mjs +320 -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 +423 -0
- package/skills/inkbone/src/core/formatter.mjs +241 -0
- package/skills/inkbone/src/core/ledger-manager.mjs +843 -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 +1710 -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 +430 -0
- package/skills/inkbone/src/evaluation.mjs +311 -0
- package/skills/inkbone/src/evidence-validator.mjs +15 -0
- package/skills/inkbone/src/exporter.mjs +142 -0
- package/skills/inkbone/src/formatter.mjs +34 -0
- package/skills/inkbone/src/importer.mjs +230 -0
- package/skills/inkbone/src/index.mjs +134 -0
- package/skills/inkbone/src/ledger-manager.mjs +22 -0
- package/skills/inkbone/src/mcp-server.mjs +950 -0
- package/skills/inkbone/src/normalizer.mjs +73 -0
- package/skills/inkbone/src/profiler.mjs +17 -0
- package/skills/inkbone/src/rule-engine.mjs +91 -0
- package/skills/inkbone/src/rule-stats.mjs +142 -0
- package/skills/inkbone/src/style-profiler.mjs +25 -0
- package/src/aigc-guard.mjs +83 -0
- package/src/auditor.mjs +24 -0
- package/src/benchmark-runner.mjs +71 -0
- package/src/boundary-compiler.mjs +60 -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/aigc-guard.mjs +387 -0
- package/src/core/auditor.mjs +1074 -0
- package/src/core/boundary-compiler.mjs +526 -0
- package/src/core/browser-doctor.mjs +320 -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 +423 -0
- package/src/core/formatter.mjs +241 -0
- package/src/core/ledger-manager.mjs +843 -0
- package/src/core/normalizer.mjs +517 -0
- package/src/core/profiler.mjs +686 -0
- package/src/core/rule-engine.mjs +1710 -0
- package/src/core/style-profiler.mjs +229 -0
- package/src/detector.mjs +270 -0
- package/src/doctor.mjs +430 -0
- package/src/evaluation.mjs +311 -0
- package/src/evidence-validator.mjs +15 -0
- package/src/exporter.mjs +142 -0
- package/src/formatter.mjs +34 -0
- package/src/importer.mjs +230 -0
- package/src/index.mjs +134 -0
- package/src/ledger-manager.mjs +22 -0
- package/src/mcp-server.mjs +950 -0
- package/src/normalizer.mjs +73 -0
- package/src/profiler.mjs +17 -0
- package/src/rule-engine.mjs +91 -0
- package/src/rule-stats.mjs +142 -0
- package/src/style-profiler.mjs +25 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { validateEvidenceReview } from "./evidence-validator.mjs";
|
|
5
|
+
|
|
6
|
+
// 可复现的伪随机数(mulberry32),用于盲读包的 X/Y 分配
|
|
7
|
+
function makeRng(seed) {
|
|
8
|
+
let a = seed >>> 0;
|
|
9
|
+
return () => {
|
|
10
|
+
a = (a + 0x6d2b79f5) >>> 0;
|
|
11
|
+
let t = a;
|
|
12
|
+
t = Math.imul(t ^ (t >>> 15), t | 1);
|
|
13
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
|
14
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function sha256(text) {
|
|
19
|
+
return crypto.createHash("sha256").update(text, "utf8").digest("hex");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 从文件名里取第一个阿拉伯数字作为配对键,取不到时用排序位置
|
|
23
|
+
function pairKey(filePath, index) {
|
|
24
|
+
const match = path.basename(filePath).match(/\d+/u);
|
|
25
|
+
return match ? String(Number(match[0])) : `#${index + 1}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 去掉正文里的 Markdown 标题行,避免标题里的版本号泄露给读者
|
|
29
|
+
export function stripHeadings(text) {
|
|
30
|
+
return text
|
|
31
|
+
.split(/\r?\n/u)
|
|
32
|
+
.filter((line) => !/^\s*#/u.test(line))
|
|
33
|
+
.join("\n")
|
|
34
|
+
.replace(/^\s+/u, "");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 把 A、B 两组章节按章号配对,随机分配成 X / Y
|
|
38
|
+
export function buildBlindPack(aFiles, bFiles, options = {}) {
|
|
39
|
+
const seed = Number.isFinite(options.seed) ? options.seed : Date.now() % 2147483647;
|
|
40
|
+
const rng = makeRng(seed);
|
|
41
|
+
const mapA = new Map(aFiles.map((f, i) => [pairKey(f, i), f]));
|
|
42
|
+
const mapB = new Map(bFiles.map((f, i) => [pairKey(f, i), f]));
|
|
43
|
+
let keys = [...mapA.keys()].filter((k) => mapB.has(k));
|
|
44
|
+
// 两边各只有一个文件时直接配对
|
|
45
|
+
if (keys.length === 0 && aFiles.length === 1 && bFiles.length === 1) {
|
|
46
|
+
mapA.set("1", aFiles[0]);
|
|
47
|
+
mapB.set("1", bFiles[0]);
|
|
48
|
+
keys = ["1"];
|
|
49
|
+
}
|
|
50
|
+
keys.sort((x, y) => Number(x.replace("#", "")) - Number(y.replace("#", "")));
|
|
51
|
+
// 样本对数大于等于 2 时采用受 seed 控制的半数均衡洗牌,防止小样本盲读包全部落入同侧
|
|
52
|
+
const slots = [];
|
|
53
|
+
if (keys.length === 1) {
|
|
54
|
+
slots.push(rng() < 0.5);
|
|
55
|
+
} else if (keys.length > 1) {
|
|
56
|
+
const half = Math.floor(keys.length / 2);
|
|
57
|
+
for (let i = 0; i < half; i += 1) {
|
|
58
|
+
slots.push(true, false);
|
|
59
|
+
}
|
|
60
|
+
if (keys.length % 2 === 1) {
|
|
61
|
+
slots.push(rng() < 0.5);
|
|
62
|
+
}
|
|
63
|
+
for (let i = slots.length - 1; i > 0; i -= 1) {
|
|
64
|
+
const j = Math.floor(rng() * (i + 1));
|
|
65
|
+
[slots[i], slots[j]] = [slots[j], slots[i]];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const pairs = keys.map((key, idx) => {
|
|
69
|
+
const aFile = mapA.get(key);
|
|
70
|
+
const bFile = mapB.get(key);
|
|
71
|
+
const aText = fs.readFileSync(aFile, "utf8");
|
|
72
|
+
const bText = fs.readFileSync(bFile, "utf8");
|
|
73
|
+
const xIsA = slots[idx];
|
|
74
|
+
return {
|
|
75
|
+
pair: `pair-${String(idx + 1).padStart(2, "0")}`,
|
|
76
|
+
chapterKey: key,
|
|
77
|
+
X: xIsA ? "A" : "B",
|
|
78
|
+
Y: xIsA ? "B" : "A",
|
|
79
|
+
sources: { A: aFile, B: bFile },
|
|
80
|
+
hashes: { A: sha256(aText), B: sha256(bText) },
|
|
81
|
+
texts: { A: stripHeadings(aText), B: stripHeadings(bText) },
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
const unpairedA = [...mapA.keys()].filter((k) => !mapB.has(k)).map((k) => mapA.get(k));
|
|
85
|
+
const unpairedB = [...mapB.keys()].filter((k) => !mapA.has(k)).map((k) => mapB.get(k));
|
|
86
|
+
const labels = { A: options.labelA || "A", B: options.labelB || "B" };
|
|
87
|
+
return {
|
|
88
|
+
seed,
|
|
89
|
+
labels,
|
|
90
|
+
// 记录两边各由哪个模型、哪个 skill 版本生成,方便按模型或按版本比较
|
|
91
|
+
generation: {
|
|
92
|
+
A: { label: labels.A, model: options.modelA || null },
|
|
93
|
+
B: { label: labels.B, model: options.modelB || null },
|
|
94
|
+
},
|
|
95
|
+
pairs,
|
|
96
|
+
unpaired: { A: unpairedA, B: unpairedB },
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 写出盲读包:packet/ 给读者(只有 X/Y 正文和选票),key.json 留给作者
|
|
101
|
+
export function writeBlindPack(pack, outDir, options = {}) {
|
|
102
|
+
const packetDir = path.join(outDir, "packet");
|
|
103
|
+
fs.mkdirSync(packetDir, { recursive: true });
|
|
104
|
+
const headingTemplate = options.headingTemplate || "# {{pair}} {{side}}";
|
|
105
|
+
for (const p of pack.pairs) {
|
|
106
|
+
const dir = path.join(packetDir, p.pair);
|
|
107
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
108
|
+
for (const side of ["X", "Y"]) {
|
|
109
|
+
const heading = headingTemplate.replace("{{pair}}", p.pair).replace("{{side}}", side);
|
|
110
|
+
fs.writeFileSync(path.join(dir, `${side}.md`), `${heading}\n\n${p.texts[p[side]]}\n`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const ballot = {
|
|
114
|
+
kind: "inkbone-ballot",
|
|
115
|
+
reader: "",
|
|
116
|
+
pairs: pack.pairs.map((p) => ({ pair: p.pair, choice: "", skimX: [], skimY: [], notes: "" })),
|
|
117
|
+
};
|
|
118
|
+
fs.writeFileSync(path.join(packetDir, "ballot.json"), JSON.stringify(ballot, null, 2) + "\n");
|
|
119
|
+
if (options.instructions) {
|
|
120
|
+
fs.writeFileSync(path.join(packetDir, "README.md"), options.instructions);
|
|
121
|
+
}
|
|
122
|
+
const key = {
|
|
123
|
+
kind: "inkbone-blind-key",
|
|
124
|
+
createdAt: new Date().toISOString(),
|
|
125
|
+
seed: pack.seed,
|
|
126
|
+
labels: pack.labels,
|
|
127
|
+
generation: pack.generation || null,
|
|
128
|
+
pairs: pack.pairs.map(({ texts: _t, ...rest }) => rest),
|
|
129
|
+
unpaired: pack.unpaired,
|
|
130
|
+
};
|
|
131
|
+
const keyPath = path.join(outDir, "key.json");
|
|
132
|
+
fs.writeFileSync(keyPath, JSON.stringify(key, null, 2) + "\n");
|
|
133
|
+
return { packetDir, keyPath, pairCount: pack.pairs.length };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 双侧符号检验 p 值(不计平局)
|
|
137
|
+
export function signTestPValue(wins, losses) {
|
|
138
|
+
const n = wins + losses;
|
|
139
|
+
if (n === 0) return 1;
|
|
140
|
+
const k = Math.min(wins, losses);
|
|
141
|
+
let logC = 0;
|
|
142
|
+
let tail = 0;
|
|
143
|
+
for (let i = 0; i <= k; i += 1) {
|
|
144
|
+
if (i > 0) logC += Math.log(n - i + 1) - Math.log(i);
|
|
145
|
+
tail += Math.exp(logC - n * Math.LN2);
|
|
146
|
+
}
|
|
147
|
+
return Math.min(1, Math.round(2 * tail * 10000) / 10000);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 汇总读者选票:每组的选择映射回 A/B,统计胜率、平局与跳读引文
|
|
151
|
+
export function scoreBallots(key, ballots, options = {}) {
|
|
152
|
+
const byPair = new Map(key.pairs.map((p) => [p.pair, p]));
|
|
153
|
+
const texts = options.texts || null;
|
|
154
|
+
const tally = { A: 0, B: 0, tie: 0, blank: 0 };
|
|
155
|
+
const skim = { A: 0, B: 0 };
|
|
156
|
+
const invalidQuotes = [];
|
|
157
|
+
const perPair = new Map();
|
|
158
|
+
for (const ballot of ballots) {
|
|
159
|
+
for (const entry of ballot.pairs || []) {
|
|
160
|
+
const p = byPair.get(entry.pair);
|
|
161
|
+
if (!p) continue;
|
|
162
|
+
const row = perPair.get(entry.pair) || { pair: entry.pair, A: 0, B: 0, tie: 0 };
|
|
163
|
+
const choice = String(entry.choice || "").trim().toUpperCase();
|
|
164
|
+
if (choice === "X" || choice === "Y") {
|
|
165
|
+
tally[p[choice]] += 1;
|
|
166
|
+
row[p[choice]] += 1;
|
|
167
|
+
} else if (choice === "TIE" || choice === "=" || choice === "SAME") {
|
|
168
|
+
tally.tie += 1;
|
|
169
|
+
row.tie += 1;
|
|
170
|
+
} else {
|
|
171
|
+
tally.blank += 1;
|
|
172
|
+
}
|
|
173
|
+
for (const side of ["X", "Y"]) {
|
|
174
|
+
const quotes = entry[`skim${side}`] || [];
|
|
175
|
+
const version = p[side];
|
|
176
|
+
skim[version] += quotes.length;
|
|
177
|
+
if (texts && texts[entry.pair]) {
|
|
178
|
+
const body = texts[entry.pair][version].replace(/\s+/gu, "");
|
|
179
|
+
for (const q of quotes) {
|
|
180
|
+
if (!body.includes(String(q).replace(/\s+/gu, ""))) {
|
|
181
|
+
invalidQuotes.push({ reader: ballot.reader || "", pair: entry.pair, side, quote: String(q).slice(0, 40) });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
perPair.set(entry.pair, row);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const decided = tally.A + tally.B;
|
|
190
|
+
return {
|
|
191
|
+
kind: "inkbone-blind-score",
|
|
192
|
+
labels: key.labels,
|
|
193
|
+
generation: key.generation || null,
|
|
194
|
+
ballots: ballots.length,
|
|
195
|
+
tally,
|
|
196
|
+
winRate: {
|
|
197
|
+
A: decided ? Math.round((tally.A / decided) * 1000) / 1000 : null,
|
|
198
|
+
B: decided ? Math.round((tally.B / decided) * 1000) / 1000 : null,
|
|
199
|
+
},
|
|
200
|
+
signTestP: signTestPValue(tally.A, tally.B),
|
|
201
|
+
skimMarks: skim,
|
|
202
|
+
invalidQuotes,
|
|
203
|
+
perPair: [...perPair.values()],
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// 读回 key.json 对应的原文(去标题后),用于核对选票里的跳读引文
|
|
208
|
+
export function loadPairTexts(key) {
|
|
209
|
+
const texts = {};
|
|
210
|
+
for (const p of key.pairs) {
|
|
211
|
+
const entry = {};
|
|
212
|
+
for (const side of ["A", "B"]) {
|
|
213
|
+
const file = p.sources?.[side];
|
|
214
|
+
entry[side] = file && fs.existsSync(file) ? stripHeadings(fs.readFileSync(file, "utf8")) : "";
|
|
215
|
+
}
|
|
216
|
+
texts[p.pair] = entry;
|
|
217
|
+
}
|
|
218
|
+
return texts;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// 校验审读 JSON 后存档:<dir>/<章节名>/<时间>-<kind>.json,记录正文哈希,正文改过就能看出来
|
|
222
|
+
export function saveReview(chapterPath, reviewPayload, options = {}) {
|
|
223
|
+
const chapterText = fs.readFileSync(chapterPath, "utf8");
|
|
224
|
+
const validation = validateEvidenceReview(chapterText, reviewPayload);
|
|
225
|
+
if (!validation.valid && !options.force) {
|
|
226
|
+
return { saved: false, validation };
|
|
227
|
+
}
|
|
228
|
+
const stem = path.basename(chapterPath).replace(/\.[^.]+$/u, "");
|
|
229
|
+
const baseDir = options.dir || path.join(path.dirname(chapterPath), "_reviews");
|
|
230
|
+
const dir = path.join(baseDir, stem);
|
|
231
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
232
|
+
const savedAt = options.now || new Date();
|
|
233
|
+
const stamp = savedAt.toISOString().replace(/[-:]/gu, "").replace(/\..+$/u, "");
|
|
234
|
+
const kind = options.kind || "review";
|
|
235
|
+
const file = path.join(dir, `${stamp}-${kind}.json`);
|
|
236
|
+
const record = {
|
|
237
|
+
meta: {
|
|
238
|
+
kind,
|
|
239
|
+
// reviewerModel:产出这份审读的模型;writerModel:写这一章正文的模型
|
|
240
|
+
reviewerModel: options.reviewerModel || null,
|
|
241
|
+
writerModel: options.writerModel || null,
|
|
242
|
+
chapterFile: path.resolve(chapterPath),
|
|
243
|
+
chapterSha256: sha256(chapterText),
|
|
244
|
+
savedAt: savedAt.toISOString(),
|
|
245
|
+
validation: { valid: validation.valid, checkedCount: validation.checkedCount, issues: validation.issues.length },
|
|
246
|
+
},
|
|
247
|
+
review: reviewPayload,
|
|
248
|
+
};
|
|
249
|
+
fs.writeFileSync(file, JSON.stringify(record, null, 2) + "\n");
|
|
250
|
+
return { saved: true, file, validation };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// 统计存档审读:按章节和类型分组,列出各类别条数,并给出最近两次的变化
|
|
254
|
+
export function summarizeReviews(files) {
|
|
255
|
+
const records = [];
|
|
256
|
+
for (const file of files) {
|
|
257
|
+
let data;
|
|
258
|
+
try {
|
|
259
|
+
data = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
260
|
+
} catch {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (!data || !data.meta || !data.review) continue;
|
|
264
|
+
const counts = {};
|
|
265
|
+
for (const item of data.review.items || []) {
|
|
266
|
+
const key = `${item.category}:${item.severity || "pass"}`;
|
|
267
|
+
counts[key] = (counts[key] || 0) + 1;
|
|
268
|
+
}
|
|
269
|
+
records.push({
|
|
270
|
+
file,
|
|
271
|
+
chapter: path.basename(data.meta.chapterFile || "").replace(/\.[^.]+$/u, ""),
|
|
272
|
+
kind: data.meta.kind,
|
|
273
|
+
savedAt: data.meta.savedAt,
|
|
274
|
+
chapterSha256: data.meta.chapterSha256,
|
|
275
|
+
reviewerModel: data.meta.reviewerModel || null,
|
|
276
|
+
writerModel: data.meta.writerModel || null,
|
|
277
|
+
counts,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
records.sort((a, b) => String(a.savedAt).localeCompare(String(b.savedAt)));
|
|
281
|
+
const groups = new Map();
|
|
282
|
+
for (const r of records) {
|
|
283
|
+
const g = `${r.chapter}|${r.kind}`;
|
|
284
|
+
if (!groups.has(g)) groups.set(g, []);
|
|
285
|
+
groups.get(g).push(r);
|
|
286
|
+
}
|
|
287
|
+
const trends = [];
|
|
288
|
+
for (const [g, list] of groups) {
|
|
289
|
+
if (list.length < 2) continue;
|
|
290
|
+
const [prev, last] = list.slice(-2);
|
|
291
|
+
const keys = new Set([...Object.keys(prev.counts), ...Object.keys(last.counts)]);
|
|
292
|
+
const delta = {};
|
|
293
|
+
for (const k of keys) {
|
|
294
|
+
const d = (last.counts[k] || 0) - (prev.counts[k] || 0);
|
|
295
|
+
if (d !== 0) delta[k] = d;
|
|
296
|
+
}
|
|
297
|
+
const [chapter, kind] = g.split("|");
|
|
298
|
+
// 换了审读模型时,条数变化可能来自模型差异,不一定是正文变好或变差
|
|
299
|
+
trends.push({
|
|
300
|
+
chapter,
|
|
301
|
+
kind,
|
|
302
|
+
from: prev.savedAt,
|
|
303
|
+
to: last.savedAt,
|
|
304
|
+
textChanged: prev.chapterSha256 !== last.chapterSha256,
|
|
305
|
+
reviewerChanged: (prev.reviewerModel || null) !== (last.reviewerModel || null),
|
|
306
|
+
writerChanged: (prev.writerModel || null) !== (last.writerModel || null),
|
|
307
|
+
delta,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
return { kind: "inkbone-review-stats", records, trends };
|
|
311
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { validateEvidenceReview as validateEvidenceReviewCore } from "./core/evidence-validator.mjs";
|
|
2
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
3
|
+
|
|
4
|
+
// 校验审稿编辑输出的 JSON 报告是否严格具备原文举证且未越权干预纯文笔风格
|
|
5
|
+
export function validateEvidenceReview(
|
|
6
|
+
chapterText,
|
|
7
|
+
reviewPayload,
|
|
8
|
+
customLingConfig = null
|
|
9
|
+
) {
|
|
10
|
+
return validateEvidenceReviewCore(
|
|
11
|
+
chapterText,
|
|
12
|
+
reviewPayload,
|
|
13
|
+
customLingConfig || loadLinguisticsConfig()
|
|
14
|
+
);
|
|
15
|
+
}
|
package/src/exporter.mjs
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Node 端网文平台投稿清洗与整卷导出入口(支持起点/番茄/七猫/晋江)
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { loadLinguisticsConfig, loadPlatformsConfig } from "./config-loader.mjs";
|
|
5
|
+
import { collectTextFiles } from "./calibrator.mjs";
|
|
6
|
+
import { parseChapterNumberAndTitle } from "./importer.mjs";
|
|
7
|
+
import {
|
|
8
|
+
resolvePlatformConfig,
|
|
9
|
+
formatChapterForPlatform as formatChapterForPlatformCore,
|
|
10
|
+
exportChapterEntries as exportChapterEntriesCore,
|
|
11
|
+
buildStoreZipBuffer,
|
|
12
|
+
buildSubmissionDocxBytes,
|
|
13
|
+
} from "./core/exporter.mjs";
|
|
14
|
+
|
|
15
|
+
export { resolvePlatformConfig, buildStoreZipBuffer, buildSubmissionDocxBytes };
|
|
16
|
+
|
|
17
|
+
// 列出所有内置投稿平台预设
|
|
18
|
+
export function listPlatforms(customPath = null) {
|
|
19
|
+
const cfg = loadPlatformsConfig(customPath);
|
|
20
|
+
return Object.values(cfg.platforms || {}).map((p) => ({
|
|
21
|
+
id: p.id,
|
|
22
|
+
title: p.title,
|
|
23
|
+
minHan: p.minHan,
|
|
24
|
+
maxHan: p.maxHan,
|
|
25
|
+
submissionMinHan: p.submissionMinHan ?? 20000,
|
|
26
|
+
defaultIndent: Boolean(p.defaultIndent),
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 清洗单章正文为指定平台投稿格式
|
|
31
|
+
export function formatChapterForPlatform(rawText, options = {}) {
|
|
32
|
+
const lingConfig = options.linguisticsConfig || loadLinguisticsConfig();
|
|
33
|
+
const platformsConfig = options.platformsConfig || loadPlatformsConfig(options.platformsPath);
|
|
34
|
+
const spec = resolvePlatformConfig(platformsConfig, options.platform);
|
|
35
|
+
return formatChapterForPlatformCore(rawText, spec, lingConfig, options);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 批量清洗并导出文件或目录(按章号自然排序;支持 --out 分章目录、--merge-out 整卷合并或 --check 仅预检)
|
|
39
|
+
export function exportChapters(targetPaths, options = {}) {
|
|
40
|
+
const inputs = Array.isArray(targetPaths) ? targetPaths : [targetPaths];
|
|
41
|
+
const files = collectTextFiles(inputs);
|
|
42
|
+
if (files.length === 0) {
|
|
43
|
+
throw new Error("No .md or .txt files found for export.");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const lingConfig = options.linguisticsConfig || loadLinguisticsConfig();
|
|
47
|
+
const platformsConfig = options.platformsConfig || loadPlatformsConfig(options.platformsPath);
|
|
48
|
+
const spec = resolvePlatformConfig(platformsConfig, options.platform);
|
|
49
|
+
|
|
50
|
+
const rawEntries = files.map((filePath, idx) => {
|
|
51
|
+
const text = fs.readFileSync(filePath, "utf8");
|
|
52
|
+
const parsed = parseChapterNumberAndTitle(filePath, text, lingConfig);
|
|
53
|
+
return {
|
|
54
|
+
idx,
|
|
55
|
+
filePath,
|
|
56
|
+
name: path.basename(filePath),
|
|
57
|
+
chapterNumber: parsed.chapterNumber,
|
|
58
|
+
text,
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
rawEntries.sort((a, b) => {
|
|
62
|
+
const na = a.chapterNumber ?? Number.MAX_SAFE_INTEGER;
|
|
63
|
+
const nb = b.chapterNumber ?? Number.MAX_SAFE_INTEGER;
|
|
64
|
+
return na - nb || a.idx - b.idx;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const result = exportChapterEntriesCore(rawEntries, spec, lingConfig, options);
|
|
68
|
+
const writtenFiles = [];
|
|
69
|
+
|
|
70
|
+
if (!options.check) {
|
|
71
|
+
if (options.outDir) {
|
|
72
|
+
const absOutDir = path.resolve(options.outDir);
|
|
73
|
+
fs.mkdirSync(absOutDir, { recursive: true });
|
|
74
|
+
result.chapters.forEach((ch) => {
|
|
75
|
+
const baseName = ch.name.replace(/\.md$/iu, ".txt");
|
|
76
|
+
const dest = path.join(absOutDir, baseName);
|
|
77
|
+
fs.writeFileSync(dest, ch.output, "utf8");
|
|
78
|
+
writtenFiles.push(dest);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (options.mergeOut) {
|
|
82
|
+
const absMerge = path.resolve(options.mergeOut);
|
|
83
|
+
fs.mkdirSync(path.dirname(absMerge), { recursive: true });
|
|
84
|
+
fs.writeFileSync(absMerge, result.mergedText, "utf8");
|
|
85
|
+
writtenFiles.push(absMerge);
|
|
86
|
+
}
|
|
87
|
+
if (options.docxOut) {
|
|
88
|
+
const absDocx = path.resolve(options.docxOut);
|
|
89
|
+
fs.mkdirSync(path.dirname(absDocx), { recursive: true });
|
|
90
|
+
const outlineText =
|
|
91
|
+
options.outlineText ||
|
|
92
|
+
(options.outlinePath && fs.existsSync(path.resolve(options.outlinePath))
|
|
93
|
+
? fs.readFileSync(path.resolve(options.outlinePath), "utf8")
|
|
94
|
+
: "");
|
|
95
|
+
const docxBytes = buildSubmissionDocxBytes(result, {
|
|
96
|
+
bookTitle: options.bookTitle || "",
|
|
97
|
+
outlineText,
|
|
98
|
+
});
|
|
99
|
+
fs.writeFileSync(absDocx, docxBytes);
|
|
100
|
+
writtenFiles.push(absDocx);
|
|
101
|
+
}
|
|
102
|
+
if (options.zipOut) {
|
|
103
|
+
const absZip = path.resolve(options.zipOut);
|
|
104
|
+
fs.mkdirSync(path.dirname(absZip), { recursive: true });
|
|
105
|
+
const zipEntries = result.chapters.map((ch) => ({
|
|
106
|
+
name: ch.name.replace(/\.md$/iu, ".txt"),
|
|
107
|
+
data: ch.output,
|
|
108
|
+
}));
|
|
109
|
+
zipEntries.push({
|
|
110
|
+
name: `${result.platform}-merged.txt`,
|
|
111
|
+
data: result.mergedText,
|
|
112
|
+
});
|
|
113
|
+
const zipBytes = buildStoreZipBuffer(zipEntries);
|
|
114
|
+
fs.writeFileSync(absZip, zipBytes);
|
|
115
|
+
writtenFiles.push(absZip);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
platform: result.platform,
|
|
121
|
+
platformTitle: result.platformTitle,
|
|
122
|
+
chapterCount: result.chapterCount,
|
|
123
|
+
totalHan: result.totalHan,
|
|
124
|
+
outOfRangeCount: result.outOfRangeCount,
|
|
125
|
+
submissionMinHan: result.submissionMinHan,
|
|
126
|
+
submissionReady: result.submissionReady,
|
|
127
|
+
submissionShortfallHan: result.submissionShortfallHan,
|
|
128
|
+
checkOnly: Boolean(options.check),
|
|
129
|
+
writtenFiles,
|
|
130
|
+
chapters: result.chapters.map((c) => ({
|
|
131
|
+
name: c.name,
|
|
132
|
+
title: c.title,
|
|
133
|
+
hanCount: c.hanCount,
|
|
134
|
+
paragraphCount: c.paragraphCount,
|
|
135
|
+
expectedRange: c.expectedRange,
|
|
136
|
+
lengthStatus: c.lengthStatus,
|
|
137
|
+
normalizationFindings: c.normalizationFindings,
|
|
138
|
+
...(options.includeOutput ? { output: c.output } : {}),
|
|
139
|
+
})),
|
|
140
|
+
...(options.includeMerged ? { mergedText: result.mergedText } : {}),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Node 端报告格式化与精准改稿 Prompt 生成入口:自动加载本地双语文案配置
|
|
2
|
+
import { loadMessagesConfig } from "./config-loader.mjs";
|
|
3
|
+
import {
|
|
4
|
+
resolveLocaleBundle,
|
|
5
|
+
formatAuditMarkdown as formatAuditMarkdownCore,
|
|
6
|
+
formatDoctorMarkdown as formatDoctorMarkdownCore,
|
|
7
|
+
buildTargetedRewritePrompt as buildTargetedRewritePromptCore,
|
|
8
|
+
} from "./core/formatter.mjs";
|
|
9
|
+
|
|
10
|
+
export { resolveLocaleBundle };
|
|
11
|
+
|
|
12
|
+
// 将单章审计报告格式化为双语 Markdown
|
|
13
|
+
export function formatAuditMarkdown(report, options = {}) {
|
|
14
|
+
return formatAuditMarkdownCore(report, {
|
|
15
|
+
...options,
|
|
16
|
+
messagesConfig: options.messagesConfig || loadMessagesConfig(options.messagesPath),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 将整书四维体检报告格式化为双语 Markdown
|
|
21
|
+
export function formatDoctorMarkdown(diagnosis, options = {}) {
|
|
22
|
+
return formatDoctorMarkdownCore(diagnosis, {
|
|
23
|
+
...options,
|
|
24
|
+
messagesConfig: options.messagesConfig || loadMessagesConfig(options.messagesPath),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 生成可直接贴入网页大模型聊天框的精准局部改稿 Prompt
|
|
29
|
+
export function buildTargetedRewritePrompt(chapterText, auditReport, options = {}) {
|
|
30
|
+
return buildTargetedRewritePromptCore(chapterText, auditReport, {
|
|
31
|
+
...options,
|
|
32
|
+
messagesConfig: options.messagesConfig || loadMessagesConfig(options.messagesPath),
|
|
33
|
+
});
|
|
34
|
+
}
|