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,73 @@
|
|
|
1
|
+
// 零 Token 确定性排版与标点清洗器(严格零汉字代码,规则词条来自 JSON 配置)
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { collectTextFiles } from "./calibrator.mjs";
|
|
5
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
6
|
+
import {
|
|
7
|
+
normalizeProseText as normalizeProseTextCore,
|
|
8
|
+
stripMarkdownEmphasis as stripMarkdownEmphasisCore,
|
|
9
|
+
} from "./core/normalizer.mjs";
|
|
10
|
+
|
|
11
|
+
// 零 Token 确定性清洗正文中的 Markdown 星号、分隔线与非标省略号/破折号
|
|
12
|
+
export function normalizeProseText(rawContent, options = {}) {
|
|
13
|
+
return normalizeProseTextCore(rawContent, {
|
|
14
|
+
...options,
|
|
15
|
+
lingConfig: options.lingConfig || loadLinguisticsConfig(),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 仅剥离受保护区间之外的 Markdown 加粗与斜体星号,用于边界与锚点匹配
|
|
20
|
+
export function stripMarkdownEmphasis(
|
|
21
|
+
rawContent,
|
|
22
|
+
whitelistLiterals = [],
|
|
23
|
+
lingConfig = null
|
|
24
|
+
) {
|
|
25
|
+
return stripMarkdownEmphasisCore(
|
|
26
|
+
rawContent,
|
|
27
|
+
whitelistLiterals,
|
|
28
|
+
lingConfig || loadLinguisticsConfig()
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 批量检查或清洗目录下所有小说文件(check 模式只读不写回)
|
|
33
|
+
export function normalizeFiles(targetPaths, options = {}) {
|
|
34
|
+
const filePaths = collectTextFiles([].concat(targetPaths || []));
|
|
35
|
+
const lingConfig = options.lingConfig || loadLinguisticsConfig();
|
|
36
|
+
const isCheck = Boolean(options.check);
|
|
37
|
+
let filesChanged = 0;
|
|
38
|
+
let totalFindings = 0;
|
|
39
|
+
const files = [];
|
|
40
|
+
|
|
41
|
+
for (const absPath of filePaths) {
|
|
42
|
+
const raw = fs.readFileSync(absPath, "utf8");
|
|
43
|
+
const res = normalizeProseText(raw, {
|
|
44
|
+
lingConfig,
|
|
45
|
+
whitelistLiterals: options.whitelistLiterals || [],
|
|
46
|
+
stripMarkdownEmphasis: Boolean(options.stripMarkdownEmphasis),
|
|
47
|
+
fixNarrationEmDash: Boolean(options.fixNarrationEmDash),
|
|
48
|
+
});
|
|
49
|
+
totalFindings += res.findingCount;
|
|
50
|
+
if (!isCheck && res.changed) {
|
|
51
|
+
fs.writeFileSync(absPath, res.output, "utf8");
|
|
52
|
+
filesChanged += 1;
|
|
53
|
+
}
|
|
54
|
+
if (res.findingCount > 0) {
|
|
55
|
+
files.push({
|
|
56
|
+
file: path.basename(absPath),
|
|
57
|
+
path: absPath,
|
|
58
|
+
findingCount: res.findingCount,
|
|
59
|
+
changed: !isCheck && res.changed,
|
|
60
|
+
findings: res.findings,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
pass: !(isCheck && totalFindings > 0),
|
|
67
|
+
check: isCheck,
|
|
68
|
+
filesScanned: filePaths.length,
|
|
69
|
+
filesChanged,
|
|
70
|
+
totalFindings,
|
|
71
|
+
files,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
2
|
+
import { countHan, profileText as profileTextCore } from "./core/profiler.mjs";
|
|
3
|
+
|
|
4
|
+
export { countHan };
|
|
5
|
+
|
|
6
|
+
// 对输入章节或语料执行全维度计算语言学指纹画像分析
|
|
7
|
+
export function profileText(
|
|
8
|
+
rawContent,
|
|
9
|
+
customLingConfig = null,
|
|
10
|
+
ruleOverrides = null
|
|
11
|
+
) {
|
|
12
|
+
return profileTextCore(
|
|
13
|
+
rawContent,
|
|
14
|
+
customLingConfig || loadLinguisticsConfig(),
|
|
15
|
+
ruleOverrides
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
2
|
+
import {
|
|
3
|
+
countVisibleChars,
|
|
4
|
+
maskWhitelistLiterals,
|
|
5
|
+
getQuotedRanges,
|
|
6
|
+
maskQuotedText,
|
|
7
|
+
stripSpokenDialogue,
|
|
8
|
+
dedupContainedHits,
|
|
9
|
+
computeTailStartIndex,
|
|
10
|
+
scanParagraphRuleSet,
|
|
11
|
+
evaluateHitsWithDensity,
|
|
12
|
+
scanCrossParagraphParallel,
|
|
13
|
+
runDensityTics,
|
|
14
|
+
extractBodyParagraphLines as extractBodyParagraphLinesCore,
|
|
15
|
+
runDegenerationChecks,
|
|
16
|
+
checkOutlineCopy as checkOutlineCopyCore,
|
|
17
|
+
parseChineseOrArabicNumber,
|
|
18
|
+
checkCharCountClaims as checkCharCountClaimsCore,
|
|
19
|
+
checkOutlineContract as checkOutlineContractCore,
|
|
20
|
+
checkCalendarSpanContradictions as checkCalendarSpanContradictionsCore,
|
|
21
|
+
checkGoldenOpeningPacing as checkGoldenOpeningPacingCore,
|
|
22
|
+
} from "./core/rule-engine.mjs";
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
countVisibleChars,
|
|
26
|
+
maskWhitelistLiterals,
|
|
27
|
+
getQuotedRanges,
|
|
28
|
+
maskQuotedText,
|
|
29
|
+
stripSpokenDialogue,
|
|
30
|
+
dedupContainedHits,
|
|
31
|
+
computeTailStartIndex,
|
|
32
|
+
scanParagraphRuleSet,
|
|
33
|
+
evaluateHitsWithDensity,
|
|
34
|
+
scanCrossParagraphParallel,
|
|
35
|
+
runDensityTics,
|
|
36
|
+
runDegenerationChecks,
|
|
37
|
+
parseChineseOrArabicNumber,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// 提取用于语言学画像与规则扫描的含汉字正文自然段
|
|
41
|
+
export function extractBodyParagraphLines(rawContent, customLingConfig = null) {
|
|
42
|
+
return extractBodyParagraphLinesCore(
|
|
43
|
+
rawContent,
|
|
44
|
+
customLingConfig || loadLinguisticsConfig()
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 检测正文是否大段照搬章节细纲文字(支持白名单原话/复沓锚句豁免)
|
|
49
|
+
export function checkOutlineCopy(chapterText, outlineText, options = {}) {
|
|
50
|
+
return checkOutlineCopyCore(chapterText, outlineText, {
|
|
51
|
+
...options,
|
|
52
|
+
lingConfig: options.lingConfig || loadLinguisticsConfig(),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 校验引号相邻句的“短短 X 字 / 这 X 个字”字数宣称是否与引号内实际字数一致
|
|
57
|
+
export function checkCharCountClaims(
|
|
58
|
+
rawContent,
|
|
59
|
+
customLingConfig = null,
|
|
60
|
+
whitelistLiterals = []
|
|
61
|
+
) {
|
|
62
|
+
return checkCharCountClaimsCore(
|
|
63
|
+
rawContent,
|
|
64
|
+
customLingConfig || loadLinguisticsConfig(),
|
|
65
|
+
whitelistLiterals
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 校验章节细纲是否缺失核心情节要素或残留未填占位符
|
|
70
|
+
export function checkOutlineContract(outlineText, options = {}) {
|
|
71
|
+
return checkOutlineContractCore(outlineText, {
|
|
72
|
+
...options,
|
|
73
|
+
lingConfig: options.lingConfig || loadLinguisticsConfig(),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 校验同章内的历法月日跨度是否与“半个月”宣称自相矛盾
|
|
78
|
+
export function checkCalendarSpanContradictions(rawContent, customLingConfig = null) {
|
|
79
|
+
return checkCalendarSpanContradictionsCore(
|
|
80
|
+
rawContent,
|
|
81
|
+
customLingConfig || loadLinguisticsConfig()
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 校验黄金三章首屏是否存在无对白且无即时冲突的慢热开局
|
|
86
|
+
export function checkGoldenOpeningPacing(rawContent, customLingConfig = null) {
|
|
87
|
+
return checkGoldenOpeningPacingCore(
|
|
88
|
+
rawContent,
|
|
89
|
+
customLingConfig || loadLinguisticsConfig()
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadGenresConfig,
|
|
3
|
+
loadLinguisticsConfig,
|
|
4
|
+
resolveGenre,
|
|
5
|
+
} from "./config-loader.mjs";
|
|
6
|
+
import { profileText } from "./profiler.mjs";
|
|
7
|
+
import { scanParagraphRuleSet } from "./rule-engine.mjs";
|
|
8
|
+
|
|
9
|
+
// 判定阈值:人类文本每万字命中达到 tasteMinPer10k 且 AI/人类比值低于 markerMinRatio,视为口味规则
|
|
10
|
+
const DEFAULTS = {
|
|
11
|
+
markerMinRatio: 3,
|
|
12
|
+
markerMinAiHits: 3,
|
|
13
|
+
tasteMinPer10k: 1,
|
|
14
|
+
minReliableHumanHan: 20000,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// 按审计器同样的顺序合并三层规则,返回带 family 的规则清单
|
|
18
|
+
export function collectRuleFamilies(options = {}) {
|
|
19
|
+
const lingConfig = options.linguisticsConfig || loadLinguisticsConfig();
|
|
20
|
+
const genresConfig = loadGenresConfig(options.genresPath);
|
|
21
|
+
const genrePack = options.genre ? resolveGenre(options.genre, options.genresPath) : null;
|
|
22
|
+
const project = options.projectRules || null;
|
|
23
|
+
const disabled = project ? project.disabledRuleIds : new Set();
|
|
24
|
+
const families = {
|
|
25
|
+
cliche: [
|
|
26
|
+
...lingConfig.compiledRegex.forbiddenCliches,
|
|
27
|
+
...(genrePack ? genrePack.compiledClicheRules : []),
|
|
28
|
+
...(project ? project.clicheRules : []),
|
|
29
|
+
],
|
|
30
|
+
symmetric: [
|
|
31
|
+
...lingConfig.compiledRegex.symmetricSkeletons,
|
|
32
|
+
...(project ? project.symmetricSkeletons : []),
|
|
33
|
+
],
|
|
34
|
+
register: [
|
|
35
|
+
...(genrePack ? genrePack.compiledRegisterRules : []),
|
|
36
|
+
...(project ? project.registerRules : []),
|
|
37
|
+
],
|
|
38
|
+
filler: [
|
|
39
|
+
...genresConfig.compiledUniversalFillers,
|
|
40
|
+
...(genrePack ? genrePack.compiledFillerRules : []),
|
|
41
|
+
...(project ? project.fillerRules : []),
|
|
42
|
+
],
|
|
43
|
+
rhetorical: [
|
|
44
|
+
...(lingConfig.compiledRegex.rhetoricalRules || []),
|
|
45
|
+
...(genrePack ? genrePack.compiledRhetoricalRules || [] : []),
|
|
46
|
+
...(project ? project.rhetoricalRules || [] : []),
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
const rules = [];
|
|
50
|
+
for (const [family, list] of Object.entries(families)) {
|
|
51
|
+
for (const rule of list) {
|
|
52
|
+
if (!rule || !rule.regex || disabled.has(rule.id)) continue;
|
|
53
|
+
rules.push({ family, rule });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { lingConfig, genre: genrePack ? genrePack.id : null, rules };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 统计一组文本里每条规则的命中次数(逐条单独扫描,不做跨规则去重)
|
|
60
|
+
function countCorpus(texts, ruleEntries, lingConfig) {
|
|
61
|
+
const counts = new Map();
|
|
62
|
+
let totalHan = 0;
|
|
63
|
+
const scanOpts = {
|
|
64
|
+
quoteMaskRegexes: lingConfig.compiledRegex.quoteMaskRegexes || [],
|
|
65
|
+
quoteMaskChar: lingConfig.tokens.quoteMaskChar || "?",
|
|
66
|
+
visibleCharRegex: lingConfig.compiledRegex.visibleCharGlobal || lingConfig.compiledRegex.hanCharGlobal,
|
|
67
|
+
};
|
|
68
|
+
for (const text of texts) {
|
|
69
|
+
const { metrics, diagnostics } = profileText(text, lingConfig);
|
|
70
|
+
totalHan += metrics.totalHan;
|
|
71
|
+
for (const { rule } of ruleEntries) {
|
|
72
|
+
// tail600 窗口规则在统计时按全文扫描,避免短样本全部落在窗口外
|
|
73
|
+
const scanRule = rule.window === "tail600" ? { ...rule, window: undefined } : rule;
|
|
74
|
+
const hits = scanParagraphRuleSet(diagnostics.paragraphs, [scanRule], scanOpts);
|
|
75
|
+
if (hits.length > 0) counts.set(rule.id, (counts.get(rule.id) || 0) + hits.length);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { counts, totalHan };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 对比人类文本与 AI 稿,给每条规则打上 ai-marker / taste / inconclusive / silent 判定
|
|
82
|
+
export function computeRuleStats(humanTexts, aiTexts, options = {}) {
|
|
83
|
+
const cfg = { ...DEFAULTS, ...(options.thresholds || {}) };
|
|
84
|
+
const { lingConfig, genre, rules } = collectRuleFamilies(options);
|
|
85
|
+
const human = countCorpus(humanTexts, rules, lingConfig);
|
|
86
|
+
const ai = countCorpus(aiTexts, rules, lingConfig);
|
|
87
|
+
const per10k = (n, han) => (han > 0 ? Math.round((n / han) * 1e5) / 10 : 0);
|
|
88
|
+
const rows = rules.map(({ family, rule }) => {
|
|
89
|
+
const humanHits = human.counts.get(rule.id) || 0;
|
|
90
|
+
const aiHits = ai.counts.get(rule.id) || 0;
|
|
91
|
+
const humanRate = per10k(humanHits, human.totalHan);
|
|
92
|
+
const aiRate = per10k(aiHits, ai.totalHan);
|
|
93
|
+
// 加 0.5 平滑后比较每万字命中率
|
|
94
|
+
const smoothedHuman = ((humanHits + 0.5) / Math.max(human.totalHan, 1)) * 1e4;
|
|
95
|
+
const smoothedAi = ((aiHits + 0.5) / Math.max(ai.totalHan, 1)) * 1e4;
|
|
96
|
+
const ratio = Math.round((smoothedAi / smoothedHuman) * 10) / 10;
|
|
97
|
+
let verdict = "inconclusive";
|
|
98
|
+
if (humanHits === 0 && aiHits === 0) verdict = "silent";
|
|
99
|
+
else if (humanRate >= cfg.tasteMinPer10k && ratio < cfg.markerMinRatio) verdict = "taste";
|
|
100
|
+
else if (ratio >= cfg.markerMinRatio && aiHits >= cfg.markerMinAiHits) verdict = "ai-marker";
|
|
101
|
+
return {
|
|
102
|
+
id: rule.id,
|
|
103
|
+
family,
|
|
104
|
+
layer: rule.layer || "universal",
|
|
105
|
+
humanHits,
|
|
106
|
+
aiHits,
|
|
107
|
+
humanPer10k: humanRate,
|
|
108
|
+
aiPer10k: aiRate,
|
|
109
|
+
ratio,
|
|
110
|
+
verdict,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
const order = { taste: 0, inconclusive: 1, "ai-marker": 2, silent: 3 };
|
|
114
|
+
rows.sort((a, b) => order[a.verdict] - order[b.verdict] || b.humanHits - a.humanHits || b.aiHits - a.aiHits);
|
|
115
|
+
return {
|
|
116
|
+
kind: "inkbone-rule-stats",
|
|
117
|
+
genre,
|
|
118
|
+
human: { docs: humanTexts.length, han: human.totalHan },
|
|
119
|
+
ai: { docs: aiTexts.length, han: ai.totalHan },
|
|
120
|
+
reliable: human.totalHan >= cfg.minReliableHumanHan,
|
|
121
|
+
thresholds: cfg,
|
|
122
|
+
summary: rows.reduce((acc, r) => ({ ...acc, [r.verdict]: (acc[r.verdict] || 0) + 1 }), {}),
|
|
123
|
+
rules: rows,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 把统计结果渲染成 Markdown 表格(默认隐藏 silent 规则)
|
|
128
|
+
export function formatRuleStatsMarkdown(stats, options = {}) {
|
|
129
|
+
const shown = stats.rules.filter((r) => options.all || r.verdict !== "silent");
|
|
130
|
+
const lines = [
|
|
131
|
+
`human: ${stats.human.docs} docs / ${stats.human.han} han; ai: ${stats.ai.docs} docs / ${stats.ai.han} han; reliable: ${stats.reliable}`,
|
|
132
|
+
`summary: ${JSON.stringify(stats.summary)}`,
|
|
133
|
+
"",
|
|
134
|
+
"| verdict | rule | family | layer | human hits | ai hits | human /10k | ai /10k | ratio |",
|
|
135
|
+
"| :--- | :--- | :--- | :--- | ---: | ---: | ---: | ---: | ---: |",
|
|
136
|
+
...shown.map(
|
|
137
|
+
(r) =>
|
|
138
|
+
`| ${r.verdict} | ${r.id} | ${r.family} | ${r.layer} | ${r.humanHits} | ${r.aiHits} | ${r.humanPer10k} | ${r.aiPer10k} | ${r.ratio} |`
|
|
139
|
+
),
|
|
140
|
+
];
|
|
141
|
+
return lines.join("\n");
|
|
142
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Node 端安全拆书与文风节奏画像入口:自动加载本地语言学、预设与双语文案配置
|
|
2
|
+
import {
|
|
3
|
+
loadLinguisticsConfig,
|
|
4
|
+
loadPresetsConfig,
|
|
5
|
+
loadMessagesConfig,
|
|
6
|
+
} from "./config-loader.mjs";
|
|
7
|
+
import {
|
|
8
|
+
analyzeStyleProfile as analyzeStyleProfileCore,
|
|
9
|
+
formatStyleProfileMarkdown as formatStyleProfileMarkdownCore,
|
|
10
|
+
} from "./core/style-profiler.mjs";
|
|
11
|
+
|
|
12
|
+
// 从一批范文或前文章节计算纯统计节奏画像与建议 customGates(绝不输出原句)
|
|
13
|
+
export function analyzeStyleProfile(texts, options = {}) {
|
|
14
|
+
const lingConfig = options.linguisticsConfig || loadLinguisticsConfig();
|
|
15
|
+
const presetsConfig = options.presetsConfig || loadPresetsConfig(options.presetsPath);
|
|
16
|
+
return analyzeStyleProfileCore(texts, lingConfig, presetsConfig, options);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 将风格画像格式化为双语 Markdown 报告
|
|
20
|
+
export function formatStyleProfileMarkdown(profile, options = {}) {
|
|
21
|
+
return formatStyleProfileMarkdownCore(profile, {
|
|
22
|
+
...options,
|
|
23
|
+
messagesConfig: options.messagesConfig || loadMessagesConfig(options.messagesPath),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { collectTextFiles } from "./calibrator.mjs";
|
|
4
|
+
import {
|
|
5
|
+
classifyParagraphCadence,
|
|
6
|
+
computeCadenceEntropy,
|
|
7
|
+
measureCompoundBricks,
|
|
8
|
+
extractNumberedParagraphs,
|
|
9
|
+
evaluateWindowSlice,
|
|
10
|
+
scanChapterAigcWindows,
|
|
11
|
+
} from "./core/aigc-guard.mjs";
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
classifyParagraphCadence,
|
|
15
|
+
computeCadenceEntropy,
|
|
16
|
+
measureCompoundBricks,
|
|
17
|
+
extractNumberedParagraphs,
|
|
18
|
+
evaluateWindowSlice,
|
|
19
|
+
scanChapterAigcWindows,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// 批量扫描单章或目录的离线 280 字滑窗 AIGC 结构风险,输出汇总报告
|
|
23
|
+
export function checkFilesAigcRisk(targetPaths, options = {}) {
|
|
24
|
+
const files = collectTextFiles(targetPaths);
|
|
25
|
+
const threshold = options.threshold !== undefined ? Number(options.threshold) : 0.5;
|
|
26
|
+
const chapters = [];
|
|
27
|
+
|
|
28
|
+
for (const fp of files) {
|
|
29
|
+
const raw = fs.readFileSync(fp, "utf8");
|
|
30
|
+
const report = scanChapterAigcWindows(raw, {
|
|
31
|
+
...options,
|
|
32
|
+
threshold,
|
|
33
|
+
});
|
|
34
|
+
chapters.push({
|
|
35
|
+
file: path.basename(fp),
|
|
36
|
+
path: fp,
|
|
37
|
+
...report,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const failingChapters = chapters.filter((c) => !c.pass);
|
|
42
|
+
return {
|
|
43
|
+
pass: failingChapters.length === 0,
|
|
44
|
+
threshold,
|
|
45
|
+
filesScanned: chapters.length,
|
|
46
|
+
failingCount: failingChapters.length,
|
|
47
|
+
chapters,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 将滑窗 AIGC 预检结果格式化为直观的 Markdown 诊断报告
|
|
52
|
+
export function formatAigcCheckMarkdown(batchReport) {
|
|
53
|
+
const lines = [
|
|
54
|
+
"# InkBone Offline AIGC Window Guard",
|
|
55
|
+
"",
|
|
56
|
+
`- **Scanned**: ${batchReport.filesScanned} | **Threshold**: \`${batchReport.threshold}\` | **Status**: ${batchReport.pass ? "PASS" : `ALERT (${batchReport.failingCount} file(s))`}`,
|
|
57
|
+
"",
|
|
58
|
+
"| File | Overall Risk | Max Win Risk | Worst Span | De% / Dem% | Entropy | Sandwich% | Flagged Wins |",
|
|
59
|
+
"| :--- | ---: | ---: | :--- | :--- | ---: | ---: | ---: |",
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
for (const ch of batchReport.chapters) {
|
|
63
|
+
const w = ch.worstWindow;
|
|
64
|
+
const span = w ? `L${w.startLine}-L${w.endLine}` : "-";
|
|
65
|
+
const deDem = w ? `${w.dePer100} / ${w.demonsPer100}` : "-";
|
|
66
|
+
lines.push(
|
|
67
|
+
`| ${ch.file} | ${ch.overallRisk.toFixed(4)} | **${ch.maxWindowRisk.toFixed(4)}** | ${span} | ${deDem} | ${ch.chapterCadence.cadenceEntropy.toFixed(2)} | ${(ch.chapterCadence.sandwichRatio * 100).toFixed(0)}% | ${ch.flaggedWindows.length} |`
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (const ch of batchReport.chapters) {
|
|
72
|
+
if (ch.flaggedWindows.length === 0) continue;
|
|
73
|
+
lines.push("", `## ${ch.file}`);
|
|
74
|
+
for (const fw of ch.flaggedWindows) {
|
|
75
|
+
const reasons = fw.reasons.length > 0 ? fw.reasons.join(", ") : "elevated_composite_risk";
|
|
76
|
+
lines.push(
|
|
77
|
+
`- **L${fw.startLine}-L${fw.endLine}** (\`risk=${fw.estimatedRisk.toFixed(4)}\`, seq=\`${fw.sequence}\`, de=${fw.dePer100}, dem=${fw.demonsPer100}, brick1k=${fw.brickPer1k}): ${reasons}`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return lines.join("\n");
|
|
83
|
+
}
|
package/src/auditor.mjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadGenresConfig,
|
|
3
|
+
loadLinguisticsConfig,
|
|
4
|
+
loadPresetsConfig,
|
|
5
|
+
loadSeverityConfig,
|
|
6
|
+
loadTraditionalConfig,
|
|
7
|
+
} from "./config-loader.mjs";
|
|
8
|
+
import { auditChapterText as auditChapterTextCore } from "./core/auditor.mjs";
|
|
9
|
+
|
|
10
|
+
// Node 端审计入口:自动从本地 JSON 加载默认配置后委托给零文件系统依赖的核心引擎
|
|
11
|
+
export function auditChapterText(rawContent, options = {}) {
|
|
12
|
+
return auditChapterTextCore(rawContent, {
|
|
13
|
+
...options,
|
|
14
|
+
linguisticsConfig: options.linguisticsConfig || loadLinguisticsConfig(),
|
|
15
|
+
genresConfig: options.genresConfig || loadGenresConfig(options.genresPath),
|
|
16
|
+
presetsConfig: options.presetsConfig || loadPresetsConfig(options.presetsPath),
|
|
17
|
+
severityConfig:
|
|
18
|
+
options.severityConfig || loadSeverityConfig(options.severityPath),
|
|
19
|
+
traditionalConfig:
|
|
20
|
+
options.traditionalConfig !== undefined
|
|
21
|
+
? options.traditionalConfig
|
|
22
|
+
: loadTraditionalConfig(),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { profileText } from "./profiler.mjs";
|
|
5
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
6
|
+
|
|
7
|
+
const currentFile = fileURLToPath(import.meta.url);
|
|
8
|
+
const srcDir = path.dirname(currentFile);
|
|
9
|
+
const defaultCorpusPath = path.resolve(
|
|
10
|
+
srcDir,
|
|
11
|
+
"../benchmarks/master-corpus.json"
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
// 批量运行基准语料库与实战章节对比,生成结构化统计对照结果与 Markdown 表格
|
|
15
|
+
export function runCorpusBenchmark(options = {}) {
|
|
16
|
+
const lingConfig = loadLinguisticsConfig();
|
|
17
|
+
const corpusPath = options.corpusPath
|
|
18
|
+
? path.resolve(options.corpusPath)
|
|
19
|
+
: defaultCorpusPath;
|
|
20
|
+
// 人类语料涉及版权,不随仓库发布;文件缺失时只跑本地章节
|
|
21
|
+
const corpusData = fs.existsSync(corpusPath)
|
|
22
|
+
? JSON.parse(fs.readFileSync(corpusPath, "utf8"))
|
|
23
|
+
: { samples: [] };
|
|
24
|
+
|
|
25
|
+
const rows = [];
|
|
26
|
+
for (const sample of corpusData.samples) {
|
|
27
|
+
const { metrics } = profileText(sample.text, lingConfig);
|
|
28
|
+
rows.push({
|
|
29
|
+
id: sample.id,
|
|
30
|
+
label: sample.label,
|
|
31
|
+
group: sample.group,
|
|
32
|
+
note: sample.detectorNote || "",
|
|
33
|
+
...metrics,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 支持附带外部实战 Markdown 文件一同参与基准对比
|
|
38
|
+
for (const extra of options.extraFiles || []) {
|
|
39
|
+
const resolved = path.resolve(extra.path);
|
|
40
|
+
if (fs.existsSync(resolved)) {
|
|
41
|
+
const content = fs.readFileSync(resolved, "utf8");
|
|
42
|
+
const { metrics } = profileText(content, lingConfig);
|
|
43
|
+
rows.push({
|
|
44
|
+
id: extra.id || path.basename(resolved, ".md"),
|
|
45
|
+
label: extra.label || path.basename(resolved),
|
|
46
|
+
group: extra.group || "benchmark_chapter",
|
|
47
|
+
note: extra.note || "",
|
|
48
|
+
...metrics,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return rows;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 将基准跑分数组渲染为清晰的 Markdown 对比表格
|
|
57
|
+
export function formatBenchmarkMarkdown(rows) {
|
|
58
|
+
const header = [
|
|
59
|
+
"| Sample | Han | SentMean | CV (Burst) | Flow>=4c | Short<=10 | De/100 | MATTR-50 | Anchor% | Dash/1k | Note |",
|
|
60
|
+
"| :--- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | :--- |",
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
const lines = rows.map((r) => {
|
|
64
|
+
const flowPct = `${(r.flowingSentRatio * 100).toFixed(1)}%`;
|
|
65
|
+
const shortPct = `${(r.ultraShortSentRatio * 100).toFixed(1)}%`;
|
|
66
|
+
const anchorPct = `${(r.topicAnchorRatio * 100).toFixed(1)}%`;
|
|
67
|
+
return `| ${r.label} | ${r.totalHan} | ${r.sentLenMean} | **${r.sentLenCV}** | ${flowPct} | ${shortPct} | ${r.dePer100Han} | **${r.mattr50}** | ${anchorPct} | ${r.emDashPer1kHan} | ${r.note} |`;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return [...header, ...lines].join("\n");
|
|
71
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { loadLinguisticsConfig } from "./config-loader.mjs";
|
|
2
|
+
import {
|
|
3
|
+
compileBoundaryPacket,
|
|
4
|
+
computeBoundaryEchoRatio as computeBoundaryEchoRatioCore,
|
|
5
|
+
verifyChapterBoundaries as verifyChapterBoundariesCore,
|
|
6
|
+
checkDeceasedCharacterAppearances as checkDeceasedCharacterAppearancesCore,
|
|
7
|
+
checkUnresolvedTacticalProps,
|
|
8
|
+
checkWorldRuleViolations,
|
|
9
|
+
} from "./core/boundary-compiler.mjs";
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
compileBoundaryPacket,
|
|
13
|
+
checkUnresolvedTacticalProps,
|
|
14
|
+
checkWorldRuleViolations,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// 检查已阵亡或退场角色是否在非回忆段落中再次活跃出场
|
|
18
|
+
export function checkDeceasedCharacterAppearances(
|
|
19
|
+
chapterText,
|
|
20
|
+
ledger,
|
|
21
|
+
chapterNumber,
|
|
22
|
+
customLingConfig = null
|
|
23
|
+
) {
|
|
24
|
+
return checkDeceasedCharacterAppearancesCore(
|
|
25
|
+
chapterText,
|
|
26
|
+
ledger,
|
|
27
|
+
chapterNumber,
|
|
28
|
+
customLingConfig || loadLinguisticsConfig()
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 计算本章开篇 500 字与上一章结尾 500 字的 6-gram 重合率(防前情重演)
|
|
33
|
+
export function computeBoundaryEchoRatio(
|
|
34
|
+
chapterText,
|
|
35
|
+
previousChapterText = "",
|
|
36
|
+
customLingConfig = null
|
|
37
|
+
) {
|
|
38
|
+
return computeBoundaryEchoRatioCore(
|
|
39
|
+
chapterText,
|
|
40
|
+
previousChapterText,
|
|
41
|
+
customLingConfig || loadLinguisticsConfig()
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 对已完成章节执行硬边界、防剧透围栏与必达事实锚点的确定性代码校验
|
|
46
|
+
export function verifyChapterBoundaries(
|
|
47
|
+
chapterText,
|
|
48
|
+
ledger,
|
|
49
|
+
chapterNumber,
|
|
50
|
+
previousChapterText = "",
|
|
51
|
+
customLingConfig = null
|
|
52
|
+
) {
|
|
53
|
+
return verifyChapterBoundariesCore(
|
|
54
|
+
chapterText,
|
|
55
|
+
ledger,
|
|
56
|
+
chapterNumber,
|
|
57
|
+
previousChapterText,
|
|
58
|
+
customLingConfig || loadLinguisticsConfig()
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Node 端内存多章整书体检入口:自动加载本地配置并委托给零文件系统核心模块
|
|
2
|
+
import {
|
|
3
|
+
loadGenresConfig,
|
|
4
|
+
loadLinguisticsConfig,
|
|
5
|
+
loadPresetsConfig,
|
|
6
|
+
loadSeverityConfig,
|
|
7
|
+
loadTraditionalConfig,
|
|
8
|
+
} from "./config-loader.mjs";
|
|
9
|
+
import {
|
|
10
|
+
diagnoseChapterEntries as diagnoseChapterEntriesCore,
|
|
11
|
+
parseChapterMetaFromEntry,
|
|
12
|
+
inferGenreFromEntries,
|
|
13
|
+
} from "./core/browser-doctor.mjs";
|
|
14
|
+
|
|
15
|
+
export { parseChapterMetaFromEntry, inferGenreFromEntries };
|
|
16
|
+
|
|
17
|
+
// 对内存中的章节数组执行整书排序体检、高频规则排行与自动台账骨架生成
|
|
18
|
+
export function diagnoseChapterEntries(entries, options = {}) {
|
|
19
|
+
return diagnoseChapterEntriesCore(entries, {
|
|
20
|
+
...options,
|
|
21
|
+
linguisticsConfig: options.linguisticsConfig || loadLinguisticsConfig(),
|
|
22
|
+
genresConfig: options.genresConfig || loadGenresConfig(options.genresPath),
|
|
23
|
+
presetsConfig: options.presetsConfig || loadPresetsConfig(options.presetsPath),
|
|
24
|
+
severityConfig: options.severityConfig || loadSeverityConfig(options.severityPath),
|
|
25
|
+
traditionalConfig:
|
|
26
|
+
options.traditionalConfig !== undefined
|
|
27
|
+
? options.traditionalConfig
|
|
28
|
+
: loadTraditionalConfig(),
|
|
29
|
+
});
|
|
30
|
+
}
|