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
|
+
}
|
package/src/profiler.mjs
ADDED
|
@@ -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
|
+
}
|