dsh-novel-writer 2.0.0 → 2.0.2

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/README.en.md CHANGED
@@ -1,20 +1,104 @@
1
- # dsh-novel-writer — Novel Writing Assistant Plugin (v2.0.0)
1
+ # 📚 dsh-novel-writer — Novel Writing Assistant
2
2
 
3
- A DSH (DeepSeek Harness) bundle plugin. **v2.0.0 ships a local semantic embedding engine (bge-small-zh-v1.5 ONNX, bundled, CPU inference, 0 token cost)** — semantic capabilities without any API fees.
3
+ English | [**中文**](./README.md)
4
4
 
5
- ## Tools (14, each with an independent UI switch)
6
- novel_books / novel_chapters / novel_read / novel_keywords / novel_new_chapter / novel_import / novel_sentence_analysis / novel_sentence_config / novel_style_check / novel_plot / novel_settings / novel_summary / novel_continuity_check / **novel_semantic_search (new in v2.0.0)**
5
+ [![npm version](https://img.shields.io/npm/v/dsh-novel-writer.svg?style=flat-square&color=blue)](https://www.npmjs.com/package/dsh-novel-writer)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](LICENSE)
7
+ [![GitHub stars](https://img.shields.io/github/stars/siweina/dsh-novel-writer.svg?style=flat-square&color=orange)](https://github.com/siweina/dsh-novel-writer/stargazers)
8
+ [![GitHub release](https://img.shields.io/github/v/release/siweina/dsh-novel-writer.svg?style=flat-square)](https://github.com/siweina/dsh-novel-writer/releases)
9
+ [![DSH plugin](https://img.shields.io/badge/DSH-plugin-4b8bbe.svg?style=flat-square)](https://github.com/deepseek-ai/deepseek-harness)
7
10
 
8
- ## v2.0.0 Semantic Layer
9
- - **Local engine** (lib/embedding.js): Xenova/bge-small-zh-v1.5 (quantized), 512-dim Chinese vectors, ~23MB, bundled; @huggingface/tokenizers + onnxruntime-web (WASM), local CPU, 0 token / 0 API cost;
10
- - **Lazy load** (~0.3s first call); automatic fallback to pure-rule mode if unavailable;
11
- - **Index cache**: per-book vectors at `.novel-writer/embedding/<book>.json` — repeated searches are instant;
12
- - **novel_semantic_search**: natural-language search across the whole book (foreshadowing clues, emotional scenes, setting mentions) — matches by meaning even when keywords differ;
13
- - **novel_style_check upgrade**: adds semantic similarity (target chapter vs rest of book) alongside rule-based fingerprint similarity;
14
- - **Switch: semanticEmbedding** — default ON (probe-based: auto-enabled when the model is present); turn it off in the sidebar「写作助手功能」panel to fully return to rule-only mode.
11
+ A novel-writing assistant plugin for **DeepSeek Harness (DSH)**: chapter library management, sentence-pattern analysis, emotion purification & quantification, style checking, plot tracking, settings management, worldview/pragmatics detection, **local semantic search (0 token)**, batch import, and AI-assisted continuation writing. Zero third-party dependencies on host.
15
12
 
16
- ## History (v0.3 → v1.6)
17
- Sentence-pattern analysis; emotion purification + AI review (strong/weak lexicon, pollution caveat); emotion quantification (Valence sliding window: variance/slope/conflict + implicit imagery + complexity score); worldview/genre/theme detection (modern/western/eastern + 15 genres + 35 themes); pragmatic-style review; settings tables (5) + foreshadowing registry + summaries + continuity audit + style check; analysis cache & report export (`.novel-writer/analysis/`).
13
+ ---
18
14
 
19
- ## Size
20
- ~95MB total (23MB quantized model + 70MB runtime); zip 31MB. If disk is tight, disable the semantic switch and delete `lib/models/` + `node_modules/` to go back to rule-only.
15
+ ## Installation
16
+
17
+ **Option 1: npm (recommended)**
18
+
19
+ ```sh
20
+ dsh plugin --profile web add dsh-novel-writer
21
+ # or
22
+ npm install dsh-novel-writer
23
+ ```
24
+
25
+ **Option 2: From GitHub**
26
+
27
+ ```sh
28
+ dsh plugin --profile web add github:siweina/dsh-novel-writer#main
29
+ ```
30
+
31
+ After installing, **restart the web app** to activate (host registers 14 tools + state/reveal routes; browser mounts the "Writing Assistant" sidebar toggle panel).
32
+
33
+ ---
34
+
35
+ ## v2.0.0 New: Local Semantic Engine (0 token)
36
+
37
+ - 🧠 **Built-in Chinese semantic model** (bge-small-zh-v1.5 quantized, 23MB, shipped with the plugin): 512-dim vectors, local CPU inference, **zero API cost**;
38
+ - 🔍 **novel_semantic_search**: search the whole book with natural language for semantically related passages (foreshadowing/emotional scenes/settings), even without matching keywords;
39
+ - 📊 **Semantic style comparison**: novel_style_check adds a semantic-similarity dimension beyond rule-based fingerprints;
40
+ - 💭 **Semantic implicit emotion**: emotion prototype sentences scan the book index to find "imagery passages outside the word list";
41
+ - 🪶 Lazy loading + automatic fallback to pure-rule mode (never breaks existing features).
42
+
43
+ ---
44
+
45
+ ## Features
46
+
47
+ 1. **Chapter library**: chapters in `novels/<book>/第N章.md` (or .txt/.markdown); auto encoding detection (UTF-8/UTF-16/GBK).
48
+ 2. **Sentence-pattern analysis**: 9 categories, arrangement patterns, rhythm, emotion curve, style fingerprint + guidance, with cache & report export.
49
+ 3. **Emotion purification**: strong/weak emotion-word grading, pollution-source detection, caveat warning + AI re-verification, cleanDominant true baseline.
50
+ 4. **Emotion quantification** (v1.6.0): Valence mapping + sliding window → variance V / delta Δ / conflict index C; implicit imagery carriers + explicit-implicit conflict; complexity score + composite emotion pairs.
51
+ 5. **Style check**: chapter vs book → similarity + deviation list + advice.
52
+ 6. **Plot tracking**: foreshadowing/plot-hook registry (open/done), typed fields + auto mention tracking.
53
+ 7. **Settings management**: five tables — characters / locations / items / timeline / worldview.
54
+ 8. **Worldview & pragmatics detection**: auto cultural-baseline detection with confidence; speechStyle title/honorifics/rituals/tone norms.
55
+ 9. **Genre & theme detection**: primary/secondary themes + genre, low-frequency noise filtered.
56
+ 10. **Chapter summaries**: per-chapter digest + key events for long-book continuation.
57
+ 11. **Continuity audit**: settings conflicts + pragmatics conflicts with replacement suggestions.
58
+ 12. **Batch import**: auto-detect book names & chapter numbers, classified import.
59
+ 13. **Continuation writing**: read-first workflow; keeps style/foreshadowing/worldview consistent.
60
+ 14. **Per-tool UI toggles**: "Writing Assistant" sidebar panel (master + per-tool + feature toggles).
61
+
62
+ ---
63
+
64
+ ## Provided Tools (14)
65
+
66
+ | Tool | Description |
67
+ |------|-------------|
68
+ | `novel_books` | List all books in library |
69
+ | `novel_chapters` | List a book's chapters |
70
+ | `novel_read` | Read a chapter (paginated) |
71
+ | `novel_keywords` | Keywords: bigram/trigram/name candidates |
72
+ | `novel_new_chapter` | Create new chapter file |
73
+ | `novel_import` | Batch import manuscripts |
74
+ | `novel_sentence_analysis` | Sentence-pattern analysis |
75
+ | `novel_sentence_config` | View/set tool & feature toggles |
76
+ | `novel_style_check` | Style check (rule + semantic) |
77
+ | `novel_plot` | Plot/foreshadowing tracker |
78
+ | `novel_settings` | Settings management (+worldview) |
79
+ | `novel_summary` | Chapter summaries |
80
+ | `novel_continuity_check` | Continuity audit |
81
+ | `novel_semantic_search` | **Semantic search** (v2.0.0, local embedding, 0 token) |
82
+
83
+ ---
84
+
85
+ ## Configuration
86
+
87
+ ```yaml
88
+ - id: novel-writer
89
+ config:
90
+ root: 'D:/my-novel-library'
91
+ allowLanState: false # true = allow state save from LAN GUI access
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Data Directory
97
+
98
+ Under `<library-root>/.novel-writer/`: `plots` / `settings` / `summaries` / `analysis` / `audits` / `embedding` (semantic index cache).
99
+
100
+ ---
101
+
102
+ ## License
103
+
104
+ [MIT](./LICENSE)
package/README.md CHANGED
@@ -1,55 +1,104 @@
1
- # dsh-novel-writer — 小说写作助手插件(v2.0.0)
1
+ # 📚 dsh-novel-writer — 小说写作助手
2
2
 
3
- DSH(DeepSeek Harness)小说写作助手 bundle 插件。**v2.0.0 集成本地语义嵌入引擎(bge-small-zh-v1.5 ONNX,随插件分发,本地 CPU 推理,0 token 成本)**,在不增加任何 API 费用的前提下获得语义级能力。
3
+ [**English**](./README.en.md) | 中文
4
4
 
5
- ## 工具清单(14 个,全部带独立 UI 开关)
5
+ [![npm version](https://img.shields.io/npm/v/dsh-novel-writer.svg?style=flat-square&color=blue)](https://www.npmjs.com/package/dsh-novel-writer)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat-square)](LICENSE)
7
+ [![GitHub stars](https://img.shields.io/github/stars/siweina/dsh-novel-writer.svg?style=flat-square&color=orange)](https://github.com/siweina/dsh-novel-writer/stargazers)
8
+ [![GitHub release](https://img.shields.io/github/v/release/siweina/dsh-novel-writer.svg?style=flat-square)](https://github.com/siweina/dsh-novel-writer/releases)
9
+ [![DSH plugin](https://img.shields.io/badge/DSH-plugin-4b8bbe.svg?style=flat-square)](https://github.com/deepseek-ai/deepseek-harness)
6
10
 
7
- novel_books / novel_chapters / novel_read / novel_keywords / novel_new_chapter / novel_import / novel_sentence_analysis / novel_sentence_config / novel_style_check / novel_plot / novel_settings(设定管理)/ novel_summary(章节摘要)/ novel_continuity_check(连贯性审计)/ **novel_semantic_search(语义检索,v2.0.0 新增)**
11
+ **DeepSeek Harness (DSH)** 打造的小说写作助手插件:章节库管理、句式模式分析、情感净化与量化、风格自检、伏笔登记、设定管理、世界观/语用检测、**本地语义检索(0 token)**、批量导入与 AI 续写辅助。宿主端零第三方依赖,浏览器端仅依赖 Web GUI 自带的 react。
8
12
 
9
- ## v2.0.0 新增能力(语义层)
13
+ ---
10
14
 
11
- ### 本地语义嵌入引擎(embedding.js)
12
- - 模型:Xenova/bge-small-zh-v1.5(512 维中文向量,约 91MB),随插件分发,开箱即用;
13
- - 运行时:**@huggingface/tokenizers**(官方轻量分词,294KB 零依赖)+ onnxruntime-web(WASM 推理),本地 CPU,0 token、0 API 费用;
14
- - 懒加载:首次调用才加载(约 0.3s);加载失败自动回退纯规则,不影响任何既有功能;
15
- - 索引缓存:每书向量落盘 `.novel-writer/embedding/<书>.json`,重复检索秒开(47 万字约 3100 段,首次建索引约 20-30s,之后命中缓存)。
15
+ ## 安装
16
16
 
17
- ### 新工具:novel_semantic_search(语义检索)
18
- 用自然语言描述在全书中检索语义相关段落——找伏笔线索、情感场景、设定提及,**即使原文没有相同关键词也能命中**(如搜「压抑克制的时刻」能命中没有"压抑"二字的段落)。
17
+ **方式一:npm(推荐)**
19
18
 
20
- ### novel_style_check 升级:语义级风格对比
21
- 规则指纹相似度(句式/句长/情绪)之外,新增**语义相似度**(目标章 vs 全书其余部分向量余弦),双维度判定风格一致性。
19
+ ```sh
20
+ dsh plugin --profile web add dsh-novel-writer
21
+ # 或
22
+ npm install dsh-novel-writer
23
+ ```
22
24
 
23
- ### 功能开关:语义增强(semanticEmbedding)
24
- - **默认开启(探测式)**:模型存在即自动启用;用户可在侧边栏「写作助手功能」面板关闭,关闭后语义检索返回提示、风格检查跳过语义维度;
25
- - 关闭后插件完整回退到 v1.6.0 纯规则能力。
25
+ **方式二:从 GitHub 安装**
26
26
 
27
- ## 历史能力(v0.3 → v1.6 累积)
28
- - 句式模式分析(九类句式分布/排列/段落/句长/情感曲线/风格指纹/密度);
29
- - 情感净化 + AI 复核(强/弱情绪词分级、污染预警 caveat、强制抽查);
30
- - 情感量化(Valence 滑动窗口:方差/斜率/矛盾指数 + 隐性意象 + 复杂度评分);
31
- - 世界观/流派/题材检测(modern/western/eastern + 15 流派 + 35 题材,主副题材);
32
- - 语用级审查(称谓/客套/仪式/语气,中西/现代禁用词);
33
- - 设定管理五张表 + 伏笔登记 + 章节摘要 + 连贯性审计 + 风格自检;
34
- - 分析缓存与报告导出(`.novel-writer/analysis/`)。
27
+ ```sh
28
+ dsh plugin --profile web add github:siweina/dsh-novel-writer#main
29
+ ```
35
30
 
36
- ## 功能开关(侧边栏「写作助手功能」面板)
37
- - 总开关 enabled;autoAnalyze;14 个工具级开关;
38
- - 功能级:emotionCaveat(情感净化预警)/ genreTheme(题材与流派检测)/ emotionComplexity(情感量化)/ **semanticEmbedding(语义增强,v2.0.0)**。
31
+ 安装后**重启 web 应用**生效(宿主端注册 14 个工具与 state/reveal 路由,浏览器端挂载侧边栏「写作助手功能」开关面板)。
39
32
 
40
- ## 目录结构
41
- ```
42
- dsh-novel-writer-v2.0.0/
43
- ├── lib/
44
- │ ├── index.js # 宿主端(14 工具 + state 路由 + 开关门禁)
45
- │ ├── analysis.js # 规则引擎(句式/情感净化/情感量化/题材)
46
- │ ├── embedding.js # 本地语义嵌入引擎(bge-small-zh ONNX)
47
- │ ├── models/ # 模型文件(onnx/model.onnx 91MB + tokenizer)
48
- │ └── client.js # 浏览器端(侧边栏面板 + 全部开关)
49
- ├── node_modules/ # @huggingface/tokenizers + onnxruntime-web(随插件分发)
50
- ├── test/ # 引擎 + client + e2e 测试
51
- └── skills/novel-writing/SKILL.md # 模型使用指南
33
+ ---
34
+
35
+ ## v2.0.0 新增:本地语义引擎(0 token)
36
+
37
+ - 🧠 **内置中文语义模型**(bge-small-zh-v1.5 quantized,23MB,随插件分发):512 维向量,本地 CPU 推理,**零 API 费用**;
38
+ - 🔍 **novel_semantic_search**:用自然语言搜全书语义相关段落(伏笔/情感场景/设定提及),即使原文没有相同关键词也能命中;
39
+ - 📊 **语义级风格对比**:novel_style_check 在规则指纹之外新增语义相似度维度;
40
+ - 💭 **语义隐性情感**:情感原型句扫全书索引,发现"词表外疑似意象段落";
41
+ - 🪶 懒加载 + 失败自动回退纯规则(不影响任何既有功能)。
42
+
43
+ ---
44
+
45
+ ## 功能
46
+
47
+ 1. **章节库管理**:章节存放于 `novels/<书名>/第N章.md`(或 .txt/.markdown),编码自动探测(UTF-8/UTF-16/GBK)。
48
+ 2. **句式模式分析**:九类句式分布、排列规律、句长节奏、情感曲线、风格指纹与节奏建议,带缓存与报告导出。
49
+ 3. **情感净化**:强/弱情绪词分级、污染源检测、caveat 预警 + AI 复核闭环、cleanDominant 真实基调。
50
+ 4. **情感量化**(v1.6.0):Valence 效价映射 + 滑动窗口 → 方差 V / 斜率 Δ / 矛盾指数 C;隐性意象载体 + 显隐冲突;复杂度评分 + 复合情感共现。
51
+ 5. **风格自检**:章节 vs 全书 → 相似度 + 偏差清单 + 续写建议。
52
+ 6. **伏笔登记表**:open/done 状态、字段化登记、章节提及自动追踪。
53
+ 7. **设定管理**:人物/地点/道具/时间线/世界观 五张表。
54
+ 8. **世界观与语用检测**:自动判断文化基准(西/东/混合)+ 置信度;speechStyle 称谓/客套/仪式/语气规范。
55
+ 9. **题材与流派检测**:主副题材 + 流派识别,低频噪音自动过滤。
56
+ 10. **章节摘要**:每章摘要 + 关键事件,长书续写先读摘要。
57
+ 11. **连贯性审计**:设定矛盾 + 语用冲突候选,带建议替换。
58
+ 12. **批量导入**:原稿件自动识别书名与章节号分类导入。
59
+ 13. **续写辅助**:先读后写、保持文风/伏笔/世界观一致。
60
+ 14. **全工具 UI 开关**:侧边栏「写作助手功能」面板(总开关 + 每工具开关 + 功能开关)。
61
+
62
+ ---
63
+
64
+ ## 提供的工具(14 个)
65
+
66
+ | 工具 | 说明 |
67
+ |------|------|
68
+ | `novel_books` | 列出章节库全部作品 |
69
+ | `novel_chapters` | 列出某作品章节清单 |
70
+ | `novel_read` | 阅读某章正文(分段) |
71
+ | `novel_keywords` | 关键词:二字组/三字组/疑似人名 |
72
+ | `novel_new_chapter` | 创建新章节文件 |
73
+ | `novel_import` | 原稿件批量导入/分类 |
74
+ | `novel_sentence_analysis` | 句式模式分析(九类/情感净化/量化/曲线/指纹) |
75
+ | `novel_sentence_config` | 查看/修改工具与功能开关 |
76
+ | `novel_style_check` | 风格自检(规则+语义双维度) |
77
+ | `novel_plot` | 伏笔/剧情线登记表 |
78
+ | `novel_settings` | 设定管理(人物/地点/道具/时间线/世界观) |
79
+ | `novel_summary` | 章节摘要(长书续写辅助) |
80
+ | `novel_continuity_check` | 连贯性审计(设定矛盾+语用冲突候选) |
81
+ | `novel_semantic_search` | **语义检索**(v2.0.0,本地 embedding,0 token) |
82
+
83
+ ---
84
+
85
+ ## 配置
86
+
87
+ ```yaml
88
+ - id: novel-writer
89
+ config:
90
+ root: 'D:/我的小说库'
91
+ allowLanState: false # true=局域网访问 GUI 时也允许保存开关
52
92
  ```
53
93
 
54
- ## 体积说明
55
- **约 95MB**(模型 23MB + 运行时 70MB),zip 31MB;已移除 transformers.js/onnxruntime-node/sharp 全家桶(省 85%)。如磁盘紧张可在「语义增强」开关关闭后删除 `lib/models/` 与 `node_modules/`,插件回到纯规则模式。
94
+ ---
95
+
96
+ ## 数据目录
97
+
98
+ `<书库根>/.novel-writer/`:`plots`(伏笔)/ `settings`(设定)/ `summaries`(摘要)/ `analysis`(分析报告)/ `audits`(审计)/ `embedding`(语义索引缓存)。
99
+
100
+ ---
101
+
102
+ ## 许可证
103
+
104
+ [MIT](./LICENSE)
package/lib/index.js CHANGED
@@ -1643,10 +1643,11 @@ function registerNovelStyleCheck(ctx, config) {
1643
1643
  if (!allTexts[i]) continue;
1644
1644
  for (const p of embedding.chunkText(allTexts[i])) allChunks.push({ ...p, id: String(i) + "|" + p.id });
1645
1645
  }
1646
- let index = embedding.loadIndex(root, book + "__style");
1646
+ const styleCacheKey = book + "__style_" + String(chapterArg).replace(/[\\/:*?"<>|]/g, "_");
1647
+ let index = embedding.loadIndex(root, styleCacheKey);
1647
1648
  if (!index || index.length === 0) {
1648
1649
  index = await embedding.embedMany(allChunks);
1649
- embedding.saveIndex(root, book + "__style", index);
1650
+ embedding.saveIndex(root, styleCacheKey, index);
1650
1651
  }
1651
1652
  // 目标章段落向量 vs 其他章段落向量,平均余弦作为语义风格相似度
1652
1653
  const targetChunks = allChunks.filter((ch) => ch.id.startsWith("0|"));
@@ -1664,6 +1665,9 @@ function registerNovelStyleCheck(ctx, config) {
1664
1665
  note: semSim >= 0.55 ? "语义风格高度一致" : semSim >= 0.45 ? "语义风格中等一致" : "语义风格存在差异,注意写法口吻",
1665
1666
  enabled: true
1666
1667
  };
1668
+ } else {
1669
+ // v2.0.0 修复:样本不足时也返回对象(schema 要求 semantic 为 object)
1670
+ semantic = { enabled: false, note: "语义对比样本不足(目标章或基准章为空)" };
1667
1671
  }
1668
1672
  } catch (e) { semantic = { enabled: false, note: "语义对比失败:" + String(e).slice(0, 80) }; }
1669
1673
  } else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-novel-writer",
3
- "version": "2.0.0",
4
- "description": "小说写作助手插件(v2.0.0):本地语义嵌入(bge-small-zh ONNX,0 token)——语义检索/语义风格对比/情感量化/世界观题材流派/语用审查,14 工具全 UI 开关",
3
+ "version": "2.0.2",
4
+ "description": "小说写作助手插件(v2.0.2):本地语义嵌入(bge-small-zh ONNX,0 token)——语义检索/语义风格对比/情感量化/世界观题材流派/语用审查,14 工具全 UI 开关",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "exports": {
@@ -38,4 +38,4 @@
38
38
  "onnxruntime-web": "^1.24.3"
39
39
  },
40
40
  "license": "MIT"
41
- }
41
+ }