@waterwx/dsh-novel-forge 2.1.2 → 2.1.3

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.
@@ -87,4 +87,18 @@ export interface AiScanRuleHit {
87
87
  count: number;
88
88
  }>;
89
89
  }
90
+ /**
91
+ * 对话字符数(含引号本身)。
92
+ *
93
+ * 导出供写法指纹复用:两处必须同一口径,否则「对话占比」在两个模块里会给出不同的数。
94
+ * @param text - 任意正文。
95
+ * @returns 对话部分的总字符数。
96
+ */
97
+ export declare function dialogueCharsOf(text: string): number;
98
+ /**
99
+ * 按真实书稿的换行形态切自然段:单换行分隔,剔除 # 标题行。
100
+ * @param text - 章节正文(可含标题行)。
101
+ * @returns 自然段数组(已 trim、去空)。
102
+ */
103
+ export declare function paragraphsOf(text: string): string[];
90
104
  export declare function scanAiFlavor(text: string, rules?: readonly AiScanRuleInput[]): AiScanResult;
@@ -0,0 +1,78 @@
1
+ /** 风格指标 key(同时是比对结果的稳定标识)。 */
2
+ export type StyleMetricKey = 'avgSentenceLength' | 'sentenceLengthCv' | 'shortSentenceRatio' | 'dialogueRatio' | 'avgParagraphLength' | 'imageryPer1000';
3
+ /** 一份文本的风格指标。 */
4
+ export interface StyleFingerprint {
5
+ /** 参与统计的字符数 */
6
+ chars: number;
7
+ /** 句子数 */
8
+ sentences: number;
9
+ /** 句均长(字符) */
10
+ avgSentenceLength: number;
11
+ /** 句长变异系数(越小越平;节奏起伏的代理) */
12
+ sentenceLengthCv: number;
13
+ /** 短句占比(句长 <= 12 字) */
14
+ shortSentenceRatio: number;
15
+ /** 对话占比(0-1) */
16
+ dialogueRatio: number;
17
+ /** 自然段均长(字符) */
18
+ avgParagraphLength: number;
19
+ /** 意象密度:每千字的比喻/意象标记词次数 */
20
+ imageryPer1000: number;
21
+ }
22
+ /** 一个指标的比对结果。 */
23
+ export interface StyleDeviation {
24
+ metric: StyleMetricKey;
25
+ /** 中文名,直接用于提示词 */
26
+ label: string;
27
+ reference: number;
28
+ actual: number;
29
+ /** 相对偏差(actual - reference)/ reference */
30
+ relative: number;
31
+ /** 偏高还是偏低 */
32
+ direction: 'higher' | 'lower';
33
+ /** 是否超出该指标的容忍度 */
34
+ significant: boolean;
35
+ }
36
+ /**
37
+ * 从文本抽取风格指纹。
38
+ * @param text - 任意正文(样本文本或章节正文;调用方需先剥掉标题行)。
39
+ * @returns 风格指标;文本短于 {@link MIN_CHARS} 时返回零值。
40
+ */
41
+ export declare function extractStyleFingerprint(text: string): StyleFingerprint;
42
+ /**
43
+ * 比对两份指纹。
44
+ *
45
+ * 参照值为 0 的指标直接跳过 —— 例如样本里本来就没有对话,此时「相对偏差」没有意义,
46
+ * 硬算会得到无穷大,反而制造假警报。
47
+ * @param reference - 参照指纹(写法样本)。
48
+ * @param actual - 本章指纹。
49
+ * @returns 每个可比指标一条结果(含是否显著)。
50
+ */
51
+ export declare function compareStyleFingerprint(reference: StyleFingerprint, actual: StyleFingerprint): StyleDeviation[];
52
+ /**
53
+ * 合并多份指纹:逐指标取**中位数**。
54
+ *
55
+ * 为什么是中位数而不是平均值:单章指标会被极端章拉偏(一个通篇无对话的章能把平均对话
56
+ * 占比拽下去),中位数对离群值不敏感。这也正是「用本书已过审章节当中位数基线」比
57
+ * 「用单一样本」更稳的原因 —— 样本自身长什么样会整个混进参照里。
58
+ * @param items - 多章指纹(过短的会被剔除,见 sentences === 0)。
59
+ * @returns 合并后的参照指纹;没有可用输入时返回零值指纹。
60
+ */
61
+ export declare function mergeFingerprints(items: readonly StyleFingerprint[]): StyleFingerprint;
62
+ /**
63
+ * 渲染**生成端**的风格目标(区间形式)。
64
+ * @param reference - 写法样本的指纹。
65
+ * @returns 可注入写作 prompt 的文本;样本过短时返回空串。
66
+ */
67
+ export declare function renderFingerprintTargets(reference: StyleFingerprint): string;
68
+ /**
69
+ * 渲染**审稿端**的风格比对(事实锚点)。
70
+ *
71
+ * 没有显著偏差时会**明确写出「没有可量化的风格偏离」**——否则模型会为了凑维度而
72
+ * 凭印象报一条「文风不符」,那正是这类审查最容易产出的假问题。
73
+ * @param reference - 写法样本的指纹。
74
+ * @param actual - 本章指纹。
75
+ * @param deviations - {@link compareStyleFingerprint} 的结果。
76
+ * @returns 可注入审稿 prompt 的文本;样本过短时返回空串。
77
+ */
78
+ export declare function renderFingerprintComparison(reference: StyleFingerprint, actual: StyleFingerprint, deviations: StyleDeviation[], sourceLabel?: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@waterwx/dsh-novel-forge",
3
3
  "description": "AI 编译纯文本小说工作台 for the dsh web GUI: import a novel outline (docx/text), plan volumes & chapters with LLM, generate chapter by chapter (3000-4000 chars each), auto AI review & book audit, and export the full book as Markdown/TXT into your chosen output folder.",
4
- "version": "2.1.2",
4
+ "version": "2.1.3",
5
5
  "type": "module",
6
6
  "author": "waterwx",
7
7
  "repository": {