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,128 @@
|
|
|
1
|
+
// 纯内存网文平台投稿清洗与整卷导出模块(零文件系统依赖,供 Node CLI、MCP 与浏览器共用)
|
|
2
|
+
import { normalizeProseText } from "./normalizer.mjs";
|
|
3
|
+
import { countHan } from "./profiler.mjs";
|
|
4
|
+
|
|
5
|
+
// 解析目标平台预设对象
|
|
6
|
+
export function resolvePlatformConfig(platformsConfig, platformId) {
|
|
7
|
+
const key = platformId || platformsConfig?.defaultPlatform || "qidian";
|
|
8
|
+
const spec = platformsConfig?.platforms?.[key];
|
|
9
|
+
if (!spec) {
|
|
10
|
+
const valid = Object.keys(platformsConfig?.platforms || {}).join(", ");
|
|
11
|
+
throw new Error(`Unknown export platform "${key}". Available platforms: ${valid}`);
|
|
12
|
+
}
|
|
13
|
+
return spec;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 剥离文首 YAML Frontmatter 与 HTML 注释,保留干净可发布正文
|
|
17
|
+
function stripNonPublishMetadata(rawText) {
|
|
18
|
+
let out = String(rawText || "").replace(/\r\n/gu, "\n");
|
|
19
|
+
out = out.replace(/^---\n[\s\S]*?\n---\n*/u, "");
|
|
20
|
+
out = out.replace(/<!--[\s\S]*?-->/gu, "");
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 将单章 Markdown 正文清洗为符合指定网文平台(起点/番茄/七猫/晋江)投稿习惯的纯文本
|
|
25
|
+
export function formatChapterForPlatform(rawText, platformSpec, lingConfig, options = {}) {
|
|
26
|
+
if (!platformSpec || !lingConfig) {
|
|
27
|
+
throw new Error("platformSpec and lingConfig are required for formatChapterForPlatform.");
|
|
28
|
+
}
|
|
29
|
+
const cleanedMeta = stripNonPublishMetadata(rawText);
|
|
30
|
+
const norm = normalizeProseText(cleanedMeta, {
|
|
31
|
+
lingConfig,
|
|
32
|
+
stripMarkdownEmphasis: platformSpec.stripMarkdownEmphasis !== false,
|
|
33
|
+
fixNarrationEmDash: Boolean(options.fixEmDash ?? platformSpec.fixNarrationEmDash),
|
|
34
|
+
whitelistLiterals: options.whitelistLiterals || [],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const useIndent =
|
|
38
|
+
options.indent !== undefined ? Boolean(options.indent) : Boolean(platformSpec.defaultIndent);
|
|
39
|
+
const indentStr = platformSpec.indentString || "\u3000\u3000";
|
|
40
|
+
const blankLines = Number.isFinite(platformSpec.blankLinesBetweenParagraphs)
|
|
41
|
+
? platformSpec.blankLinesBetweenParagraphs
|
|
42
|
+
: 1;
|
|
43
|
+
const separator = "\n".repeat(blankLines + 1);
|
|
44
|
+
const hanRegex = lingConfig.compiledRegex.hanCharGlobal;
|
|
45
|
+
const headingRe = lingConfig.chineseNumerals?.chapterHeadingParseRegex
|
|
46
|
+
? new RegExp(lingConfig.chineseNumerals.chapterHeadingParseRegex, "u")
|
|
47
|
+
: null;
|
|
48
|
+
|
|
49
|
+
const rawLines = norm.output.split("\n");
|
|
50
|
+
const outParagraphs = [];
|
|
51
|
+
let extractedTitle = "";
|
|
52
|
+
|
|
53
|
+
for (const rawLine of rawLines) {
|
|
54
|
+
let line = rawLine.trim();
|
|
55
|
+
if (!line) continue;
|
|
56
|
+
// 跳过纯 Markdown 分隔线与围栏代码块标记
|
|
57
|
+
if (/^[-*_]{3,}$/u.test(line) || /^```/u.test(line)) continue;
|
|
58
|
+
// 剥离引用前缀符号
|
|
59
|
+
line = line.replace(/^>\s*/u, "").trim();
|
|
60
|
+
if (!line) continue;
|
|
61
|
+
|
|
62
|
+
const isMdHeading = /^#{1,6}\s+/u.test(line);
|
|
63
|
+
if (isMdHeading && platformSpec.stripMarkdownHeadings !== false) {
|
|
64
|
+
const stripped = line.replace(/^#{1,6}\s+/u, "").trim();
|
|
65
|
+
if (!extractedTitle && stripped) {
|
|
66
|
+
extractedTitle = stripped;
|
|
67
|
+
}
|
|
68
|
+
if (stripped) {
|
|
69
|
+
outParagraphs.push(stripped);
|
|
70
|
+
}
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!extractedTitle && outParagraphs.length === 0 && headingRe && headingRe.test(line)) {
|
|
75
|
+
extractedTitle = line;
|
|
76
|
+
outParagraphs.push(line);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 剥离原有全角/半角缩进后按平台配置重新规范段首缩进
|
|
81
|
+
const bodyText = line.replace(/^[\s\u3000]+/u, "");
|
|
82
|
+
outParagraphs.push(useIndent ? `${indentStr}${bodyText}` : bodyText);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const output = outParagraphs.join(separator) + (outParagraphs.length > 0 ? "\n" : "");
|
|
86
|
+
const hanCount = countHan(output, hanRegex);
|
|
87
|
+
const minHan = platformSpec.minHan ?? 2000;
|
|
88
|
+
const maxHan = platformSpec.maxHan ?? 5000;
|
|
89
|
+
const lengthStatus =
|
|
90
|
+
hanCount < minHan ? "too_short" : hanCount > maxHan ? "too_long" : "ok";
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
platform: platformSpec.id,
|
|
94
|
+
title: extractedTitle,
|
|
95
|
+
hanCount,
|
|
96
|
+
paragraphCount: outParagraphs.length,
|
|
97
|
+
expectedRange: [minHan, maxHan],
|
|
98
|
+
lengthStatus,
|
|
99
|
+
normalizationFindings: norm.findingCount,
|
|
100
|
+
output,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 批量导出多章稿件,输出逐章结果与整卷合并纯文本
|
|
105
|
+
export function exportChapterEntries(entries, platformSpec, lingConfig, options = {}) {
|
|
106
|
+
const chapters = (entries || []).map((entry) => {
|
|
107
|
+
const formatted = formatChapterForPlatform(entry.text, platformSpec, lingConfig, options);
|
|
108
|
+
return {
|
|
109
|
+
name: entry.name,
|
|
110
|
+
...formatted,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const joiner = platformSpec.chapterSeparator || "\n\n\n";
|
|
115
|
+
const mergedText = chapters.map((c) => c.output.trimEnd()).join(joiner) + (chapters.length > 0 ? "\n" : "");
|
|
116
|
+
const totalHan = chapters.reduce((acc, c) => acc + c.hanCount, 0);
|
|
117
|
+
const outOfRangeCount = chapters.filter((c) => c.lengthStatus !== "ok").length;
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
platform: platformSpec.id,
|
|
121
|
+
platformTitle: platformSpec.title,
|
|
122
|
+
chapterCount: chapters.length,
|
|
123
|
+
totalHan,
|
|
124
|
+
outOfRangeCount,
|
|
125
|
+
chapters,
|
|
126
|
+
mergedText,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// 纯内存报告格式化与精准改稿 Prompt 生成模块(零文件系统依赖,供 Node CLI、MCP 与浏览器共用)
|
|
2
|
+
|
|
3
|
+
// 解析指定语言的本地化词典(默认回退至配置 defaultLang 或 zh)
|
|
4
|
+
export function resolveLocaleBundle(messagesConfig, lang = null) {
|
|
5
|
+
const locales = messagesConfig?.locales || {};
|
|
6
|
+
const fallbackKey = messagesConfig?.defaultLang || "zh";
|
|
7
|
+
const key = lang && locales[lang] ? lang : locales[fallbackKey] ? fallbackKey : Object.keys(locales)[0];
|
|
8
|
+
return {
|
|
9
|
+
lang: key || "en",
|
|
10
|
+
bundle: locales[key] || {},
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// 模板占位符简单替换(例如 {files}、{genre})
|
|
15
|
+
function interpolate(template, vars = {}) {
|
|
16
|
+
let out = String(template || "");
|
|
17
|
+
for (const [k, v] of Object.entries(vars)) {
|
|
18
|
+
out = out.split(`{${k}}`).join(String(v ?? ""));
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// 格式化单章审计报告为人类可读 Markdown(支持中英双语)
|
|
24
|
+
export function formatAuditMarkdown(report, options = {}) {
|
|
25
|
+
const { bundle } = resolveLocaleBundle(options.messagesConfig, options.lang);
|
|
26
|
+
const s = bundle.reportStrings || {};
|
|
27
|
+
const vLabels = bundle.violationLabels || {};
|
|
28
|
+
const remedies = bundle.remedies || {};
|
|
29
|
+
const sevLabels = bundle.severityLabels || {};
|
|
30
|
+
const mLabels = bundle.metricLabels || {};
|
|
31
|
+
|
|
32
|
+
const statusText = report.pass ? s.statusPass || "PASS" : s.statusFail || "FAIL";
|
|
33
|
+
const sum = report.summary || { error: 0, warning: 0, info: 0 };
|
|
34
|
+
const m = report.metrics || {};
|
|
35
|
+
|
|
36
|
+
const lines = [
|
|
37
|
+
s.auditTitle || "# InkBone Audit Report",
|
|
38
|
+
"",
|
|
39
|
+
`- **${s.genreLabel || "Genre"}**: \`${report.genre || "general-clean"}\` | **${s.presetLabel || "Preset"}**: \`${report.preset || "default"}\` | **Status**: ${statusText} (${report.mode || "default"})`,
|
|
40
|
+
`- **${s.totalsLabel || "Summary"}**: ${s.hardErrors || "Errors"}: ${sum.error} | ${s.warnings || "Warnings"}: ${sum.warning} | ${s.infos || "Info"}: ${sum.info}`,
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
if (options.fileName) {
|
|
44
|
+
lines.splice(2, 0, `- **${s.tableFile || "File"}**: \`${options.fileName}\``);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 关键语言学指标概览
|
|
48
|
+
lines.push(
|
|
49
|
+
"",
|
|
50
|
+
s.sectionMetrics || "## Metrics",
|
|
51
|
+
`- ${mLabels.totalHan || "Han"}: ${m.totalHan ?? 0} | ${mLabels.paragraphCount || "Paragraphs"}: ${m.paragraphCount ?? 0} | ${mLabels.sentLenMean || "Mean Sent"}: ${m.sentLenMean ?? 0} | ${mLabels.sentLenCV || "CV"}: ${m.sentLenCV ?? 0} | ${mLabels.mattr50 || "MATTR-50"}: ${m.mattr50 ?? 0} | ${mLabels.dePer100Han || "De/100"}: ${m.dePer100Han ?? 0}`
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const targets = report.surgeryTargets || [];
|
|
55
|
+
const actionableViolations = (report.violations || []).filter(
|
|
56
|
+
(v) => v.severity !== "info" || options.includeInfo
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (targets.length === 0 && actionableViolations.length === 0) {
|
|
60
|
+
lines.push("", s.noIssues || "No issues detected.");
|
|
61
|
+
return lines.join("\n");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (targets.length > 0) {
|
|
65
|
+
lines.push("", s.sectionTargets || "## Line Targets");
|
|
66
|
+
for (const target of targets) {
|
|
67
|
+
const desc = target.issues
|
|
68
|
+
.map((i) => {
|
|
69
|
+
const badge = i.level === "blocking" ? `${s.blockTag || "[BLOCK]"} ` : "";
|
|
70
|
+
return `${badge}\`${i.tag}\` (${i.detail})`;
|
|
71
|
+
})
|
|
72
|
+
.join("; ");
|
|
73
|
+
lines.push(`- **${s.linePrefix || "L"}${target.line}${s.lineSuffix || ""}**: ${desc}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (actionableViolations.length > 0) {
|
|
78
|
+
lines.push("", s.sectionViolations || "## Chapter Findings");
|
|
79
|
+
for (const v of actionableViolations) {
|
|
80
|
+
const sevTag = sevLabels[v.severity] || v.severity;
|
|
81
|
+
const title = vLabels[v.code] || v.code;
|
|
82
|
+
const remedy = remedies[v.code] || v.remedy || "";
|
|
83
|
+
const suffix = remedy ? ` — ${s.remedyPrefix || ""}${remedy}` : "";
|
|
84
|
+
lines.push(`- **[${sevTag}] ${title}** (\`${v.code}\`)${suffix}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return lines.join("\n");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 格式化整书四维体检报告为 Markdown(支持中英双语与实用引导提示)
|
|
92
|
+
export function formatDoctorMarkdown(diagnosis, options = {}) {
|
|
93
|
+
const { bundle } = resolveLocaleBundle(options.messagesConfig, options.lang);
|
|
94
|
+
const s = bundle.reportStrings || {};
|
|
95
|
+
const vLabels = bundle.violationLabels || {};
|
|
96
|
+
const remedies = bundle.remedies || {};
|
|
97
|
+
const hintMap = bundle.hintMessages || {};
|
|
98
|
+
|
|
99
|
+
const lines = [
|
|
100
|
+
s.doctorTitle || "# InkBone Doctor Report",
|
|
101
|
+
"",
|
|
102
|
+
`- **${s.genreLabel || "Genre Pack"}**: \`${diagnosis.genre.id}\` (${diagnosis.genre.title}) [${diagnosis.genre.source}]`,
|
|
103
|
+
`- **${s.presetLabel || "Preset"}**: \`${diagnosis.genre.defaultPreset}\``,
|
|
104
|
+
`- **${s.formulaLabel || "Register Formula"}**: ${diagnosis.genre.registerFormula}`,
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
if (diagnosis.genre.mixedGenreFiles && diagnosis.genre.mixedGenreFiles.length > 0) {
|
|
108
|
+
const filesStr = diagnosis.genre.mixedGenreFiles
|
|
109
|
+
.map((m) => `${m.file} -> ${m.inferredGenre}`)
|
|
110
|
+
.join(", ");
|
|
111
|
+
const mixedMsg = hintMap.MIXED_GENRE_DETECTED
|
|
112
|
+
? interpolate(hintMap.MIXED_GENRE_DETECTED, { files: filesStr })
|
|
113
|
+
: `Warning: Mixed genres detected in unconfigured folder (${filesStr}); pass \`--genre\` or add \`novel.json\` per book.`;
|
|
114
|
+
lines.push(`- ${mixedMsg}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const hint of diagnosis.hints || []) {
|
|
118
|
+
const text = hintMap[hint.code] || hint.detail || hint.code;
|
|
119
|
+
lines.push(`- ${text}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (diagnosis.incremental?.active) {
|
|
123
|
+
const incTpl =
|
|
124
|
+
bundle.incrementalNote ||
|
|
125
|
+
"Incremental mode ({mode}): scanned {scanned} of {total} chapter(s).";
|
|
126
|
+
lines.push(
|
|
127
|
+
`- ${interpolate(incTpl, {
|
|
128
|
+
mode: diagnosis.incremental.mode,
|
|
129
|
+
scanned: diagnosis.incremental.scannedCount,
|
|
130
|
+
total: diagnosis.incremental.totalDiscovered,
|
|
131
|
+
})}`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const t = diagnosis.totals;
|
|
136
|
+
lines.push(
|
|
137
|
+
`- **${s.totalsLabel || "Totals"}**: ${t.chaptersScanned} ${s.chaptersUnit || "chapter(s)"} | ${s.hardErrors || "Hard Errors"}: ${t.hardErrors} | ${s.regClash || "Register Clash"}: ${t.registerCollisions} | ${s.fillers || "Fillers"}: ${t.narrativeFillers} | ${s.cliches || "AI Cliches"}: ${t.aiCliches} | ${s.rhetTics || "Rhet/Tics"}: ${t.rhetoricalPatterns + t.densityTics} | ${s.degeneration || "Degeneration"}: ${t.degenerationErrors} | ${s.metaLeaks || "Meta Leaks"}: ${t.metaLeaks} | ${s.proStreaks || "Pronoun Streaks"}: ${t.pronounStreaks}`,
|
|
138
|
+
"",
|
|
139
|
+
`| ${s.tableFile || "File"} | ${s.tableHan || "Han"} | ${s.tableErrors || "Errors"} | ${s.tableReg || "RegClash"} | ${s.tableFillers || "Fillers"} | ${s.tableCliches || "Cliches"} | ${s.tableRhet || "Rhet/Tics"} | ${s.tablePro || "ProStreak"} |`,
|
|
140
|
+
`| :--- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |`
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
for (const ch of diagnosis.chapters) {
|
|
144
|
+
const rhetTics = ch.counts.rhetoricalPatterns + ch.counts.densityTics;
|
|
145
|
+
lines.push(
|
|
146
|
+
`| ${ch.file} | ${ch.totalHan} | ${ch.summary.error} | ${ch.counts.registerCollisions} | ${ch.counts.narrativeFillers} | ${ch.counts.aiCliches} | ${rhetTics} | ${ch.maxPronounHeadStreak} |`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
for (const ch of diagnosis.chapters) {
|
|
151
|
+
if (ch.surgeryTargets.length === 0 && ch.summary.error === 0) continue;
|
|
152
|
+
lines.push("", `## ${ch.file}`);
|
|
153
|
+
for (const v of ch.violations) {
|
|
154
|
+
if (v.severity === "error") {
|
|
155
|
+
const label = vLabels[v.code] ? `${vLabels[v.code]} (${v.code})` : v.code;
|
|
156
|
+
const desc = v.details ? JSON.stringify(v.details) : remedies[v.code] || v.remedy || "";
|
|
157
|
+
lines.push(`- **${s.errorTag || "[ERROR]"} ${label}**: ${desc}`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
for (const target of ch.surgeryTargets.slice(0, 25)) {
|
|
161
|
+
const desc = target.issues
|
|
162
|
+
.map((i) => {
|
|
163
|
+
const badge = i.level === "blocking" ? `${s.blockTag || "[BLOCK]"} ` : "";
|
|
164
|
+
return `${badge}\`${i.tag}\` (${i.detail})`;
|
|
165
|
+
})
|
|
166
|
+
.join("; ");
|
|
167
|
+
lines.push(`- **${s.linePrefix || "L"}${target.line}${s.lineSuffix || ""}**: ${desc}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return lines.join("\n");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 基于单章审计结果,确定性拼装可直接粘贴至任意大模型聊天框的“精准局部改稿 Prompt”
|
|
175
|
+
export function buildTargetedRewritePrompt(chapterText, auditReport, options = {}) {
|
|
176
|
+
const { bundle } = resolveLocaleBundle(options.messagesConfig, options.lang);
|
|
177
|
+
const rp = bundle.rewritePrompt || {};
|
|
178
|
+
const s = bundle.reportStrings || {};
|
|
179
|
+
const vLabels = bundle.violationLabels || {};
|
|
180
|
+
const remedies = bundle.remedies || {};
|
|
181
|
+
const sevLabels = bundle.severityLabels || {};
|
|
182
|
+
|
|
183
|
+
const targets = auditReport?.surgeryTargets || [];
|
|
184
|
+
const actionableViolations = (auditReport?.violations || []).filter(
|
|
185
|
+
(v) => v.severity === "error" || v.severity === "warning"
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
if (targets.length === 0 && actionableViolations.length === 0) {
|
|
189
|
+
return {
|
|
190
|
+
hasIssues: false,
|
|
191
|
+
issueCount: 0,
|
|
192
|
+
prompt: rp.emptyNotice || "No issues found.",
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const rawLines = String(chapterText || "").split(/\r?\n/u);
|
|
197
|
+
const parts = [rp.header || "Revise only the flagged lines below."];
|
|
198
|
+
|
|
199
|
+
const genreLabel = options.genreTitle || auditReport?.genre || "general-clean";
|
|
200
|
+
parts.push("", interpolate(rp.genreLine || "Genre: {genre}", { genre: genreLabel }));
|
|
201
|
+
if (rp.rulesBlock) {
|
|
202
|
+
parts.push("", rp.rulesBlock);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
parts.push("", rp.issuesHeading || "### Flagged Issues");
|
|
206
|
+
|
|
207
|
+
let issueCount = 0;
|
|
208
|
+
for (const target of targets) {
|
|
209
|
+
const lineText = (rawLines[target.line - 1] || "").trim();
|
|
210
|
+
const issueDesc = target.issues
|
|
211
|
+
.map((i) => {
|
|
212
|
+
const badge = i.level === "blocking" ? `${s.blockTag || "[BLOCK]"} ` : "";
|
|
213
|
+
return `${badge}${i.tag}: ${i.detail}`;
|
|
214
|
+
})
|
|
215
|
+
.join(" | ");
|
|
216
|
+
parts.push(
|
|
217
|
+
`- ${s.linePrefix || "L"}${target.line}${s.lineSuffix || ""}: ${issueDesc}${lineText ? ` => "${lineText.slice(0, 60)}"` : ""}`
|
|
218
|
+
);
|
|
219
|
+
issueCount += target.issues.length;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
for (const v of actionableViolations) {
|
|
223
|
+
const sev = sevLabels[v.severity] || v.severity;
|
|
224
|
+
const label = vLabels[v.code] || v.code;
|
|
225
|
+
const rem = remedies[v.code] || v.remedy || "";
|
|
226
|
+
parts.push(`- [${sev}] ${label} (${v.code})${rem ? ` — ${rem}` : ""}`);
|
|
227
|
+
issueCount += 1;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
parts.push("", rp.chapterHeading || "### Chapter Text", "```markdown");
|
|
231
|
+
rawLines.forEach((line, idx) => {
|
|
232
|
+
parts.push(`L${idx + 1}: ${line}`);
|
|
233
|
+
});
|
|
234
|
+
parts.push("```");
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
hasIssues: true,
|
|
238
|
+
issueCount,
|
|
239
|
+
prompt: parts.join("\n"),
|
|
240
|
+
};
|
|
241
|
+
}
|